package org.bigdata.framework.admin.web.controller;

import java.io.File;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.bigdata.framework.admin.web.ueditor.ActionEnter;
import org.bigdata.framework.admin.web.util.CommonUrl;
import org.bigdata.framework.admin.web.util.DBUtils;
import org.bigdata.framework.admin.web.util.DateUtils;
import org.bigdata.framework.admin.web.util.DateWeek;
import org.bigdata.framework.admin.web.util.ExcelMore;
import org.bigdata.framework.admin.web.util.FileDownloadUtil;
import org.bigdata.framework.admin.web.util.MD5;
import org.bigdata.framework.admin.web.util.OpenOfficePdfConvert;
import org.bigdata.framework.admin.web.util.Pinyin4jUtils;
import org.bigdata.framework.core.model.Classes;
import org.bigdata.framework.core.model.CommonDataProperty;
import org.bigdata.framework.core.model.DataExport;
import org.bigdata.framework.core.model.DataImport;
import org.bigdata.framework.core.model.DataProperty;
import org.bigdata.framework.core.model.DataSubmit;
import org.bigdata.framework.core.model.DataType;
import org.bigdata.framework.core.model.Department;
import org.bigdata.framework.core.model.Dict;
import org.bigdata.framework.core.model.DictItem;
import org.bigdata.framework.core.model.Log;
import org.bigdata.framework.core.model.Menu;
import org.bigdata.framework.core.model.MenuButton;
import org.bigdata.framework.core.model.ObjectProperty;
import org.bigdata.framework.core.model.Permission;
import org.bigdata.framework.core.model.PermissionButton;
import org.bigdata.framework.core.model.PermissionClasses;
import org.bigdata.framework.core.model.Role;
import org.bigdata.framework.core.model.SearchHotwords;
//import org.bigdata.framework.core.model.SearchNews;
import org.bigdata.framework.core.model.SearchSortRule;
import org.bigdata.framework.core.model.SearchWeightCustoms;
import org.bigdata.framework.core.model.SearchWeightFields;
import org.bigdata.framework.core.model.ShardingDataSource;
import org.bigdata.framework.core.model.ShardingRepositoryCount;
import org.bigdata.framework.core.model.ThesauriWord;
import org.bigdata.framework.core.model.ThesauriWordCategory;
import org.bigdata.framework.core.model.ThesauriWordModule;
import org.bigdata.framework.core.model.ThesauriWordReference;
import org.bigdata.framework.core.model.ThesauriWordRelation;
import org.bigdata.framework.core.model.User;
import org.bigdata.framework.core.model.UserGroup;
import org.bigdata.framework.core.model.UserGroupRole;
import org.bigdata.framework.core.model.UserGroupUser;
import org.bigdata.framework.core.model.UserRole;
import org.bigdata.framework.core.model.Workflow;
import org.bigdata.framework.core.model.WorkflowExecute;
import org.bigdata.framework.core.model.WorkflowNode;
import org.bigdata.framework.core.protocol.IBaikeService;
import org.bigdata.framework.core.protocol.IBaseService;
import org.bigdata.framework.core.protocol.ICmsService;
import org.bigdata.framework.core.protocol.IDynamicService;
import org.bigdata.framework.core.protocol.IPublicService;
import org.bigdata.framework.core.protocol.ISearchService;
import org.bigdata.framework.core.protocol.IWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.sts.model.v20150401.AssumeRoleRequest;
import com.aliyuncs.sts.model.v20150401.AssumeRoleResponse;
import com.xxl.conf.core.XxlConfClient;

import net.sf.json.JSONObject;


@Controller
public class KnowledgeEditController extends BaseContoroller {

	@Autowired
	private IPublicService publicService;
	@Autowired
	private IBaseService baseService;
	@Autowired
	private IWordService iWordService;
	@Autowired
	private IDynamicService dynamicService ;
	@Autowired
	private ISearchService searchService;
	@Autowired 
	private ICmsService cmsService;
	@Autowired 
	private IBaikeService baikeService;
	
	private Object put;

	//公共日常记录
	public void log(Integer createUserId,String logType,String classesId,String dataId,String logText,Integer logStatus) throws Exception{
		//获得本机IP 
		InetAddress addr = InetAddress.getLocalHost();   
		String createIpAddress=addr.getHostAddress();  
		//获得时间
		String createTime = DateUtils.getDateTime();
		
		Log log=new Log();
		log.setCreateTime(createTime);
		log.setCreateUserId(createUserId);
		log.setCreateIpAddress(createIpAddress);
		log.setLogType(logType);
		log.setLogText(logText);
		log.setLogStatus(logStatus);
			
		if(classesId !=null){
			log.setClassesId(classesId);
		}
		if(dataId !=null){
			log.setDataId(dataId);
		}
		baseService.saveLog(log);
	}
	//汉字转拼音
	@RequestMapping("pinYin")
	public void pinYin(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String hanzi = request.getParameter("pinYin");
		String dp = request.getParameter("dp");
		String pinYin = Pinyin4jUtils.getetter(hanzi);
		if(!"".equals(dp)&& dp !=null){
			List<DataProperty> dataPropertyList =publicService.getDataProperty();
			for (int i = 0; i < dataPropertyList.size(); i++) {
				DataProperty dataProperty = dataPropertyList.get(i);
					if(dataProperty.getNameEn().equals(pinYin)){
						pinYin="no";
					}
			}
			System.out.println(dataPropertyList);
		}
		List<String> returnPinYin = new ArrayList<String>();
		returnPinYin.add(pinYin);
		String resultString = formatToJson(returnPinYin);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	//汉字转首字母
	@RequestMapping("hanziToinitial")
	public void hanziToinitial(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String hanzi = request.getParameter("pinYin");
		String dp = request.getParameter("dp");
		String pinYin = Pinyin4jUtils.getFirstSpell(hanzi);
		if(!"".equals(dp)&& dp !=null){
			List<DataProperty> dataPropertyList =publicService.getDataProperty();
			for (int i = 0; i < dataPropertyList.size(); i++) {
				DataProperty dataProperty = dataPropertyList.get(i);
					if(dataProperty.getNameEn().equals(pinYin)){
						pinYin="no";
					}
			}
			System.out.println(dataPropertyList);
		}
		List<String> returnPinYin = new ArrayList<String>();
		returnPinYin.add(pinYin);
		String resultString = formatToJson(returnPinYin);
		super.pringWriterToPage(resultString, "application/json", response);
	}

	
	//知识加工
	@RequestMapping("show-edit-data-class.html")
	public ModelAndView toKnowledgeEditDataClass() {
		List<DictItem> dictItemList = null;
		HashMap<String, Object> queryDictParams = new HashMap<String, Object>();
		queryDictParams.put("=,nameEn", "db");
		List<Dict> dictList = publicService.getDict(queryDictParams, 1, 1);
		if(null != dictList && dictList.size()>0){
			Dict dict = dictList.get(0);
			HashMap<String, Object> queryDictItemParams = new HashMap<String, Object>();
			queryDictItemParams.put("=,dictId", dict.getId());
			dictItemList = publicService.getDictItem(queryDictItemParams, 1, publicService.getDictItemCount(queryDictItemParams));
		}
		
		ModelAndView view = new ModelAndView();
		view.addObject("dictItemList", dictItemList);
		view.setViewName("/modules/repository/knowledge_edit_data_class");
		return view;
	}
	//知识加工用户
	@RequestMapping("knowledge-edit-data-users.html")
	public String toKnowledgeEditDataUsers() {
		return "/modules/repository/knowledge_edit_data_users";
	}
	//知识权限添加知识库
	@RequestMapping("knowledge-edit-data-addRepository.html")
	public String toKnowledgeEditDataAddRepository() {
		return "/modules/repository/knowledge_edit_data_addRepository";
	}
	//知识库历史版本
	@RequestMapping("knowledge-edit-data-versions.html")
	public String toKnowledgeEditDataVersions() {
		return "/modules/repository/knowledge_edit_data_versions";
	}
	 //流程批量撤销
	@RequestMapping("knowledge_edit_workflow_users.html")
	public String knowledgeEditWorkFlowUsers() {
		return "/modules/repository/knowledge_edit_workflow_users";
	}
	//图片
	@RequestMapping("knowledge-edit-data-detail-uploading.html")
	public String toKnowledgeEditDataClassUploading() {
		
		return "/modules/repository/knowledge_edit_data_detail_uploading";
	}
	//关联图片
	@RequestMapping("knowledge-edit-data-detai-relevanceuploading.html")
	public String toKnowledgeEditDataClassRelevanceUploading() {
		
		return "/modules/repository/knowledge_edit_data_detail_relevanceuploading";
	}
	//附件
	@RequestMapping("knowledge-edit-data-detail-adjunct.html")
	public String toKnowledgeEditDataClassadjunct() {
		
		return "/modules/repository/knowledge_edit_data_detail_adjunct";
	}
	//知识发布
	@RequestMapping("knowledge-edit-data-submit-form.html")
	public String toKnowledgeEditDataSubmitForm() {
		
		return "/modules/repository/knowledge_edit_data_submit_form";
	}
	//字典项树
	@RequestMapping("knowledge-edit-data-ztree.html")
	public String toKnowledgeEditDataZtree() {
		
		return "/modules/repository/knowledge_edit_data_ztree";
	}
	//关联字典项树
	@RequestMapping("knowledge-edit-data-relevanceztree.html")
	public String toKnowledgeEditDataRelevanceZtree() {
		
		return "/modules/repository/knowledge_edit_data_relevanceztree";
	}
	//关联字典项树
	@RequestMapping("knowledge-edit-data-relevancemultiztree.html")
	public String toknowledgeEditDataRelevancemultiztree() {
		
		return "/modules/repository/knowledge_edit_data_relevancemultiztree";
	}
	//字典树
	@RequestMapping("knowledge-edit-data-dic-ztree.html")
	public String toKnowledgeEditDataDicZtree() {
		
		return "/modules/repository/knowledge_edit_data_dic_ztree";
	}
	//图形展示
	@RequestMapping("knowledge-edit-data-graph.html")
	public String toKnowledgeEditDataGraph() {
		
		return "/modules/repository/knowledge_edit_data_graph";
	}
	//图形展示-知识加工
	@RequestMapping("knowledge-edit-data-list-graph.html")
	public String toKnowledgeEditDataListGraph() {
		return "/modules/repository/knowledge_edit_data_list_graph";
	}
	
	//菜单管理
	@RequestMapping("user-menu-manage.html")
	public String toKnowledgeEditDataUser() {
		return "/modules/repository/knowledge_edit_data_menu";
	}
	//菜单管理树
	@RequestMapping("knowledge-edit-data-menu-zTree.html")
	public String toKnowledgeEditDataMenuzTree() {
		return "/modules/repository/knowledge_edit_data_menu_zTree";
	}
	//添加菜单
	@RequestMapping("knowledge-edit-data-addmenu.html")
	public String toKnowledgeEditDataAddMenu() {
		return "/modules/repository/knowledge_edit_data_addmenu";
	}
	//修改菜单
	@RequestMapping("knowledge-edit-data-uploadmenu.html")
	public String toKnowledgeEditDataUploadMenu() {
		return "/modules/repository/knowledge_edit_data_uploadmenu";
	}
	//添加菜单按钮
	@RequestMapping("knowledge-edit-data-addmenubutton.html")
	public String toKnowledgeEditDataAddMenuButton() {
		return "/modules/repository/knowledge_edit_data_addmenubutton";
	}
	//详情菜单按钮
	@RequestMapping("knowledge-edit-data-querymenubutton.html")
	public String toKnowledgeEditDataQueryButton() {
		return "/modules/repository/knowledge_edit_data_querymenubutton";
	}
	
	//权限管理
	@RequestMapping("user-menu-jurisdiction.html")
	public String toKnowledgeEditDataJurisdiction() {
		return "/modules/repository/knowledge_edit_data_jurisdiction";
	}
	//角色管理
	@RequestMapping("user-menu-role.html")
	public String toKnowledgeEditDataRole() {
		return "/modules/repository/knowledge_edit_data_role";
	}
	//查询用户
	@RequestMapping("knowledge-edit-data-queryuser.html")
	public String toKnowledgeEditDataQueryUser() {
		return "/modules/repository/knowledge_edit_data_queryuser";
	}
	//查询用户详情
	@RequestMapping("knowledge-edit-data-queryuserdetails.html")
	public String toKnowledgeEditDataQueryUserDetails() {
		return "/modules/repository/knowledge_edit_data_userdetails";
	}
	
	//增加用户组
	@RequestMapping("knowledge-edit-data-adduser.html")
	public String toKnowledgeEditDataaddUser() {
		return "/modules/repository/knowledge_edit_data_adduser";
	}
	
	//增加用户组树状
	@RequestMapping("knowledge-edit-data-usergroup-zTree.html")
	public String toKnowledgeEditDataUserGroupzTree() {
		return "/modules/repository/knowledge_edit_data_usergroup_zTree";
	}
	//用户组管理
	@RequestMapping("user-menu-rolegroup.html")
	public String toKnowledgeEditDataRoleGroup() {
		return "/modules/repository/knowledge_edit_data_rolegroup";
	}
	//修改用户组页面
	@RequestMapping("knowledge-edit-data-uploadroleGroup.html")
	public String toKnowledgeEditDataUploadRole() {
		return "/modules/repository/knowledge_edit_data_uploadrole";
	}
	//添加用户
	@RequestMapping("knowledge-edit-data-addrole.html")
	public String toKnowledgeEditDataAddRole() {
		return "/modules/repository/knowledge_edit_data_addrole";
	}
	//添加角色
	@RequestMapping("knowledge-edit-data-saverole.html")
	public String toKnowledgeEditDataSaveRole() {
		return "/modules/repository/knowledge_edit_data_saverole";
	}
	//部門管理
	@RequestMapping("user-menu-section.html")
	public String toKnowledgeEditDataSection() {
		return "/modules/repository/knowledge_edit_data_section";
	}
	//添加部門
	@RequestMapping("knowledge-edit-data-adddepartment.html")
	public String toKnowledgeEditDataAdddepartment() {
		return "/modules/repository/knowledge_edit_data_adddepartment";
	}
	//部門树
	@RequestMapping("knowledge-edit-data-department-zTree.html")
	public String toKnowledgeEditDataDepartmentzTree() {
		return "/modules/repository/knowledge_edit_data_department_zTree";
	}
	//部門管理
	@RequestMapping("user-menu-knowledgeJurisdiction.html")
	public String toKnowledgeEditDataKnowledgeJurisdictionn() {
		return "/modules/repository/knowledge_edit_data_knowledge_jurisdiction";
	}
	//关联详情
	@RequestMapping("knowledge-edit-data-queryrelevance.html")
	public String toKnowledgeEditDataQueryRelevance() {
		return "/modules/repository/knowledge_edit_data_queryrelevance";
	}
	//前往新闻管理列表栏目树
	@RequestMapping("cms-news-list-category-ztree.html")
	public String toCmsNewsListCategoryZtree() {
		return "/modules/cms/cms_news_list_category_ztree";
	}
	//测试
	@RequestMapping("graph")
	public String graph() {
		return "/modules/repository/graph";
	}
	//统一检索---》权重配置
	@RequestMapping("search-weight-setting.html")
	public ModelAndView searchWeightSetting() {
		List<Classes> classes =publicService.getClasses();
		ModelAndView view = new ModelAndView();
		view.addObject("classes", classes);
		view.setViewName("/modules/repository/search_weight_setting");
		return view;
	}
	//权重配置---》字段新增和修改
	@RequestMapping("search-weight-fieldsAddUpload.html")
	public String searchWeightFieldsAddUpload() {
		return "/modules/repository/search_weight_fieldsAddUpload";
	}
	//权重配置---》自定义新增和修改
	@RequestMapping("search-weight-customsAddUpload.html")
	public String searchWeightCustomsAddUpload() {
		return "/modules/repository/search_weight_customsAddUpload";
	}
	//权重配置---》Classes类
	@RequestMapping("search-weight-classes-zTree.html")
	public String searchWeightClassesZTree() {
		return "/modules/repository/search_weight_classes_zTree";
	}
	//统一检索 新闻管理
	@RequestMapping("search-news-setting.html")
	public String goSearchNewsSetting() {
	    return "/modules/repository/search_news_setting";
	}
	//统一检索 新闻管理
	@RequestMapping("search-news-addUpload.html")
	public String goSearchNewsAddUpload() {
	    return "/modules/repository/search_news_addUpload";
	}
	//统一检索---》排序
	@RequestMapping("search-sort-setting.html")
	public String searchSortSetting() {
		return "/modules/repository/search_sort_setting";
	}
	//统一检索---》排序新增或修改
	@RequestMapping("search-sort-settingAddUpload.html")
	public ModelAndView searchSortSettingAddUpload() {
		ModelAndView view = new ModelAndView();
//		view.addObject("classesList", publicService.getClasses());
		view.setViewName("/modules/repository/search_sort_settingAddUpload");
		return view;
	}
	//统一检索---》排序zTree
	@RequestMapping("search_editSave_department_zTree.html")
	public String searchSortSettingZtree() {
		return "/modules/repository/search_editSave_department_zTree";
	}
	//统一检索---》热搜词
	@RequestMapping("search-hotwords.html")
	public String searchHotwords() {
		return "/modules/repository/search_hotwords";
	}
	//统一检索---》热搜词新增或修改
	@RequestMapping("search-hotwordsAddUpload.html")
	public String searchHotwordsAddUpload() {
		return "/modules/repository/search_hotwordsAddUpload";
	}
	//统一检索---》热搜词可视化
	@RequestMapping("search-hotwords-visual.html")
	public ModelAndView searchHotwordsVisual() {
		List<SearchHotwords> searchHotwords =publicService.getSearchHotwords();
		ModelAndView view = new ModelAndView();
		view.addObject("searchHotwords", searchHotwords);
		view.setViewName("/modules/repository/search_hotwords_visual");
		return view;
	}
	//统一检索---》索引管理
	@RequestMapping("search-indexManager.html")
	public String searchIndexManager() {
		return "/modules/repository/search_indexManager";
	}
	//字典项 多选树
	@RequestMapping("knowledge-edit-multi-ztree.html")
	public String toKnowledgeEditMultiZtree() {
		return "/modules/repository/knowledge_edit_multi_ztree";
	}
	//知识审核
	@RequestMapping("show-edit-data-audit.html")
	public String toknowledgeEditDataAudit() {
		return "/modules/repository/knowledge_edit_data_audit";
	}
	//阿里云上传
	@RequestMapping("knowledge-edit-aliyun-uploading.html")
	public ModelAndView knowledgeEditAliyunUploading() throws ClientException {
		IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",XxlConfClient.get("aliyun.access_key_id", ""),XxlConfClient.get("aliyun.access_key_secret", ""));
		DefaultAcsClient client = new DefaultAcsClient(profile);
		AssumeRoleResponse response = assumeRole(client,XxlConfClient.get("aliyun.role_arn", ""));
		AssumeRoleResponse.Credentials credentials = response.getCredentials();
		/*System.out.println("AccessKeyId: "+credentials.getAccessKeyId() + "\n" +
		"AccessKeySecret: "+credentials.getAccessKeySecret() + "\n" +
		"SecurityToken: "+credentials.getSecurityToken() + "\n" +
		"Expiration: "+credentials.getExpiration());*/
		ModelAndView view = new ModelAndView();
		view.addObject("accessKeyId", credentials.getAccessKeyId());
		view.addObject("accessKeySecret", credentials.getAccessKeySecret());
		view.addObject("securityToken", credentials.getSecurityToken());
		view.addObject("expiration", credentials.getExpiration());
		view.addObject("try_see", XxlConfClient.get("aliyun.try_see", ""));
		view.addObject("di_definition", XxlConfClient.get("aliyun.di_definition", ""));
		view.addObject("biao_definition", XxlConfClient.get("aliyun.biao_definition", ""));
		view.addObject("gao_definition", XxlConfClient.get("aliyun.gao_definition", ""));
		view.addObject("chao_definition", XxlConfClient.get("aliyun.chao_definition", ""));
		view.addObject("original_file", XxlConfClient.get("aliyun.original_file", ""));
		view.addObject("bucket_source", XxlConfClient.get("aliyun.bucket_source", ""));
		view.addObject("audio_full", XxlConfClient.get("aliyun.audio_full", ""));
		view.setViewName("/modules/repository/knowledge_edit_aliyun_uploading");
		return view;
	}
	//阿里云上传
	@RequestMapping("knowledge-edit-aliyun-relevance-uploading.html")
	public ModelAndView knowledgeEditAliyunRelevanceUploading() throws ClientException {
		IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",XxlConfClient.get("aliyun.access_key_id", ""),XxlConfClient.get("aliyun.access_key_secret", ""));
		DefaultAcsClient client = new DefaultAcsClient(profile);
		AssumeRoleResponse response = assumeRole(client,XxlConfClient.get("aliyun.role_arn", ""));
		AssumeRoleResponse.Credentials credentials = response.getCredentials();
		/*System.out.println("AccessKeyId: "+credentials.getAccessKeyId() + "\n" +
		"AccessKeySecret: "+credentials.getAccessKeySecret() + "\n" +
		"SecurityToken: "+credentials.getSecurityToken() + "\n" +
		"Expiration: "+credentials.getExpiration());*/
		ModelAndView view = new ModelAndView();
		view.addObject("accessKeyId", credentials.getAccessKeyId());
		view.addObject("accessKeySecret", credentials.getAccessKeySecret());
		view.addObject("securityToken", credentials.getSecurityToken());
		view.addObject("expiration", credentials.getExpiration());
		view.addObject("try_see", XxlConfClient.get("aliyun.try_see", ""));
		view.addObject("di_definition", XxlConfClient.get("aliyun.di_definition", ""));
		view.addObject("biao_definition", XxlConfClient.get("aliyun.biao_definition", ""));
		view.addObject("gao_definition", XxlConfClient.get("aliyun.gao_definition", ""));
		view.addObject("chao_definition", XxlConfClient.get("aliyun.chao_definition", ""));
		view.addObject("original_file", XxlConfClient.get("aliyun.original_file", ""));
		view.addObject("bucket_source", XxlConfClient.get("aliyun.bucket_source", ""));
		view.addObject("audio_full", XxlConfClient.get("aliyun.audio_full", ""));
		view.setViewName("/modules/repository/knowledge_edit_aliyun_relevance_uploading");
		return view;
	}
	private static AssumeRoleResponse assumeRole(DefaultAcsClient client,String roleArn)throws ClientException {
		final AssumeRoleRequest request = new AssumeRoleRequest();
		request.setVersion("2015-04-01");
		request.setMethod(MethodType.POST);
		request.setProtocol(ProtocolType.HTTPS);
		request.setDurationSeconds(3600L);
		request.setRoleArn(roleArn);
		request.setRoleSessionName("test-token");
		return client.getAcsResponse(request);
	}
	/**
	 * 显示内容
	 * zhongfeng 
	 * 2016.9.1
	 */
	@RequestMapping("knowledge-edit-data-class-ajax-right.html")
	@ResponseBody
	public void rightAll(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String astrict = request.getParameter("astrict");
		String type = request.getParameter("type");
		String daValue = request.getParameter("daValue");
		List<Classes> classesAll = null;
		LinkedHashMap<String, Object> mp = null;
		HashMap<String, Object> queryRepositoryCountParams = null;
		SimpleDateFormat  df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		List<LinkedHashMap<String, Object>> rightContent = new ArrayList<LinkedHashMap<String, Object>>();
		Integer departmentid =(Integer) request.getSession().getAttribute("departmentid");
		Integer userid =(Integer) request.getSession().getAttribute("userid");
		
		//知识加工统计
		if(userid != 1){
				// 结果集
				if("0".equals(daValue)){
					classesAll = publicService.getClasses();
				}else{
					HashMap<String, Object> queryClassesParams = new HashMap<String, Object>();
					queryClassesParams.put("%,db", daValue);
					classesAll = publicService.getClasses(queryClassesParams, 1, publicService.getClassesCount(queryClassesParams));
				}
				HashMap<String, Object> queryParams=new HashMap<String, Object>();
				queryParams.put("=,departmentId", departmentid);
				List<PermissionClasses> permissionClasses=publicService.getPermissionClasses(queryParams);
				User user =publicService.findUser(userid);
				HashMap<String, Object> queryCount=new HashMap<String, Object>();
				if(Integer.parseInt(user.getIsPrincipal().toString())!=1){
					queryCount.put("=create_user_id", userid);
				}else{
					queryCount.put("=create_org_id", departmentid);
				}
				for( Classes classes :classesAll){
					for(PermissionClasses permission:permissionClasses){
						if(classes.getId().toString().equals(permission.getClassesId().toString()) &&classes.getDisplay()==1){
							queryRepositoryCountParams = new HashMap<String, Object>();
							queryRepositoryCountParams.put("=,classes_en", classes.getNameEn());
							List<ShardingRepositoryCount> ShardingRepositoryCountList = publicService.getShardingRepositoryCount(queryRepositoryCountParams, 1, publicService.getShardingRepositoryCountCount(queryRepositoryCountParams));
							if(null != ShardingRepositoryCountList && ShardingRepositoryCountList.size()>0){
								int number=0;
								Date updateTime=null;
								for (int i = 0; i < ShardingRepositoryCountList.size(); i++) {
									ShardingRepositoryCount shardingRepositoryCount = ShardingRepositoryCountList.get(i);
									number = number+shardingRepositoryCount.getDataCount();
									Date time = df.parse(shardingRepositoryCount.getUpdateTime());//将字符串转换为date类型  
									if(null == updateTime || time.before(updateTime)){
										updateTime = time;
									}
								}
								mp.put("number", number);
								mp.put("nameZh", classes.getNameZh()+"（更新时间："+df.format(updateTime)+"）");
								mp.put("nameEn", classes.getNameEn());
								mp.put("classesId", classes.getId());
								mp.put("kind", 0);
								rightContent.add(mp);
							}else{
								mp =new LinkedHashMap<String, Object>();
								mp.put("number", dynamicService.getDynamicCount(classes.getNameEn(), queryCount));
								mp.put("nameZh", classes.getNameZh());
								mp.put("nameEn", classes.getNameEn());
								mp.put("classesId", classes.getId());
								mp.put("kind", 0);
								rightContent.add(mp);
							}
						}
					}
				}
				
				for (int i = 0; i < rightContent.size(); i++) {
					HashMap<String, Object> hasmap = rightContent.get(i);
					int classesid =(Integer) hasmap.get("classesId");
					
					for (int j = 0; j < rightContent.size(); j++) {
						HashMap<String, Object> has = rightContent.get(j);
						if(classesid == (Integer) has.get("classesId") && i !=j){
							rightContent.remove(j);
						}
					}
				}
		}else{
			// 结果集
			if("0".equals(daValue)){
				classesAll = publicService.getClasses();
			}else{
				HashMap<String, Object> queryClassesParams = new HashMap<String, Object>();
				queryClassesParams.put("%,db", daValue);
				classesAll = publicService.getClasses(queryClassesParams, 1, publicService.getClassesCount(queryClassesParams));
			}
			for( Classes classes :classesAll){
				if(classes.getDisplay() == 1){
					mp =new LinkedHashMap<String, Object>();
					queryRepositoryCountParams = new HashMap<String, Object>();
					queryRepositoryCountParams.put("=,classes_en", classes.getNameEn());
					List<ShardingRepositoryCount> ShardingRepositoryCountList = publicService.getShardingRepositoryCount(queryRepositoryCountParams, 1, publicService.getShardingRepositoryCountCount(queryRepositoryCountParams));
					if(null != ShardingRepositoryCountList && ShardingRepositoryCountList.size()>0){
						int number=0;
						Date updateTime=null;
						for (int i = 0; i < ShardingRepositoryCountList.size(); i++) {
							ShardingRepositoryCount shardingRepositoryCount = ShardingRepositoryCountList.get(i);
							number = number+shardingRepositoryCount.getDataCount();
							Date time = df.parse(shardingRepositoryCount.getUpdateTime());//将字符串转换为date类型  
							if(null == updateTime || time.before(updateTime)){
								updateTime = time;
							}
						}
						mp.put("number", number);
						mp.put("nameZh", classes.getNameZh()+"（更新时间："+df.format(updateTime)+"）");
						mp.put("nameEn", classes.getNameEn());
						mp.put("classesId", classes.getId());
						mp.put("kind", 0);
						rightContent.add(mp);
					}else{
						mp.put("number", dynamicService.getDynamicCount(classes.getNameEn(), null));
						mp.put("nameZh", classes.getNameZh());
						mp.put("nameEn", classes.getNameEn());
						mp.put("classesId", classes.getId());
						mp.put("kind", 0);
						rightContent.add(mp);
					}
				}		
			}
		}
		if("0".equals(type)){
			//字典项统计
			List<Dict> listDict =publicService.getDict();
				for (int i = 0; i < listDict.size(); i++) {
					Dict dict =listDict.get(i);
					HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
					queryParams.put("=,dictId", dict.getId());
					long dictCunt = publicService.getDictItemCount(queryParams);
					mp =new LinkedHashMap<String, Object>();
					mp.put("number", dictCunt);
					mp.put("nameZh", dict.getNameZh());
					mp.put("nameEn", dict.getNameEn());
					mp.put("classesId", dict.getId());
					mp.put("kind", 1);
					rightContent.add(mp);
				}
			
			try {
				//普通词表
				long generalWordCount =iWordService.getGeneralWordCount(null);
				LinkedHashMap<String, Object> generalWordCountMap = new LinkedHashMap<String, Object>();
					generalWordCountMap.put("number", generalWordCount);
					generalWordCountMap.put("nameZh", "普通词表");
					generalWordCountMap.put("nameEn", "putong");
					generalWordCountMap.put("classesId", "1");
					generalWordCountMap.put("kind", 2);
					rightContent.add(generalWordCountMap);
				//叙词表
				long thesauriWordCount =iWordService.getThesauriWordCount(null);
				LinkedHashMap<String, Object> thesauriWordCountMap = new LinkedHashMap<String, Object>();
					thesauriWordCountMap.put("number", thesauriWordCount);
					thesauriWordCountMap.put("nameZh", "叙词表");
					thesauriWordCountMap.put("nameEn", "xuci");
					thesauriWordCountMap.put("classesId", "2");
					thesauriWordCountMap.put("kind", 2);
					rightContent.add(thesauriWordCountMap);
				//范畴
				LinkedHashMap<String, Object> thesauriWordCategoryMap = new LinkedHashMap<String, Object>();
					thesauriWordCategoryMap.put("number", iWordService.getThesauriWordCategoryCount(null) );
					thesauriWordCategoryMap.put("nameZh", "范畴");
					thesauriWordCategoryMap.put("nameEn", "fanchou");
					thesauriWordCategoryMap.put("classesId", "3");
					thesauriWordCategoryMap.put("kind", 2);
					rightContent.add(thesauriWordCategoryMap);
			} catch (Exception e) {
				LinkedHashMap<String, Object> thesauriWordCategoryMap = new LinkedHashMap<String, Object>();
				thesauriWordCategoryMap.put("number", -1);
				thesauriWordCategoryMap.put("kind", 2);
				rightContent.add(thesauriWordCategoryMap);
			}
		}	
		String resultString = formatToJson(rightContent);
		super.pringWriterToPage(resultString, "application/json", response);
	}

	/**
	 * 知识加工-数据列表
	 * zhongfeng
	 * 2016.9.12
	 */

	
	@RequestMapping("show-edit-data-list.html")
	public ModelAndView toKnowledgeEditDataList(HttpServletRequest request) {
		String classesEn = request.getParameter("classesEn");
		String createUserId = request.getParameter("createUserId");
		String curr = request.getParameter("curr");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		String status = request.getParameter("status");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");
		
		int classesId = Integer.parseInt(request.getParameter("classesId"));
		List<User> users= publicService.getUser();
		Integer userid =(Integer) request.getSession().getAttribute("userid");
		/*
		 * 判断审核
		 */
		HashMap<String, Object> queryRoleCountParams = new HashMap<String, Object>();
		queryRoleCountParams.put("=,user_id", userid);
		queryRoleCountParams.put("=,role_id", 25);
		int audit= 0;
		List<UserRole> userRoleList= publicService.getUserRole(queryRoleCountParams);
		if(null != userRoleList && userRoleList.size()>0){
			audit = userRoleList.get(0).getId();
		}
		Cookie[] cookies = request.getCookies();
		String recordCount = null;
		if (cookies != null) {
			for (Cookie cookie : cookies) {
				if ("recordCount".equals(cookie.getName())) {
					recordCount = cookie.getValue(); // 得到筛选页数
				}
			
			}
		}
		int count=0;
		if(recordCount == null){
			count=15;
		}else{
			count=Integer.parseInt(recordCount);
		}
		List<Integer> records= new ArrayList<Integer>();
		records.add(10);
		records.add(15);
		records.add(20);
		records.add(50);
		records.add(80);
		records.add(100);
		records.add(1000);
		Classes classes = publicService.findClasses(classesId);
		String headline= classes.getNameZh();
		String describe = classes.getDescription();
		
		//分库分表
		String tableactiondTab = "";
		String tableactionTabContent = "";
		String newsTab = "";
		HashMap<String, Object> queryRepositoryCountParams = new HashMap<String, Object>();
		queryRepositoryCountParams.put("=,classes_en", classes.getNameEn());
		HashMap<String, Object> tableNameMap= new LinkedHashMap<String, Object>();
		List<ShardingRepositoryCount> ShardingRepositoryCountList = publicService.getShardingRepositoryCount(queryRepositoryCountParams, 1, publicService.getShardingRepositoryCountCount(queryRepositoryCountParams));
		for (int i = 0; i < ShardingRepositoryCountList.size(); i++) {
			ShardingRepositoryCount shardingRepositoryCount = ShardingRepositoryCountList.get(i);
			ShardingDataSource ShardingDataSource = publicService.findShardingDataSource(shardingRepositoryCount.getShardingDataSourceId());
			if(null == tableNameMap.get(ShardingDataSource.getNameEn()) || "".equals(tableNameMap.get(ShardingDataSource.getNameEn()))){
				int tepositoryCount = 0;
				for (int j = 0; j < ShardingRepositoryCountList.size(); j++) {
					ShardingRepositoryCount aShardingRepositoryCount= ShardingRepositoryCountList.get(j);
					if(aShardingRepositoryCount.getShardingDataSourceId().equals(shardingRepositoryCount.getShardingDataSourceId())){
						tepositoryCount = tepositoryCount + aShardingRepositoryCount.getDataCount();
					}
				}
				if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
					if(databaseName.equals(ShardingDataSource.getId().toString()) ){
						newsTab = ShardingDataSource.getNameEn();
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle on\" value=\""+ShardingDataSource.getNameZh()+"（"+tepositoryCount+"）\" >&nbsp;&nbsp;&nbsp;";
					}else{
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle\" value=\""+ShardingDataSource.getNameZh()+"（"+tepositoryCount+"）\" >&nbsp;&nbsp;&nbsp;";
					}
				}else {
					if(i == 0){
						newsTab = ShardingDataSource.getNameEn();
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle on\" value=\""+ShardingDataSource.getNameZh()+"（"+tepositoryCount+"）\" >&nbsp;&nbsp;&nbsp;";
					}else{
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle\" value=\""+ShardingDataSource.getNameZh()+"（"+tepositoryCount+"）\" >&nbsp;&nbsp;&nbsp;";
					}
				}
			}
			if(null == tableNameMap.get(ShardingDataSource.getNameEn()) || "".equals(tableNameMap.get(ShardingDataSource.getNameEn()))){
				tableNameMap.put(ShardingDataSource.getNameEn(), shardingRepositoryCount.getTableName());
			}else{
				tableNameMap.put(ShardingDataSource.getNameEn(),tableNameMap.get(ShardingDataSource.getNameEn())+";"+shardingRepositoryCount.getTableName());
			}
		}
		for (String tableName : tableNameMap.keySet()) {
			Object oTableName = tableNameMap.get(tableName);
			if(null != oTableName && !"".equals(oTableName)){
				String [] tableNames = oTableName.toString().split(";");
				if(tableName.equals(newsTab)){
					tableactionTabContent +="<div id=\"table-"+tableName+"-tab\" class=\"tab-pane fade in active\">"
	                                    	+"<div class=\"row\">"
	                                    	+"<div class=\"col-lg-12\">";
											for (int i = 0; i < tableNames.length; i++) {
												if(null != chartName && !"".equals(chartName)&& !"undefined".equals(chartName)){
													if(chartName.equals(tableNames[i])){
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default on\" />&nbsp;&nbsp;&nbsp;";
													}else{
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default\" />&nbsp;&nbsp;&nbsp;";
													}
												}else{
													if( i == 0){
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default on\" />&nbsp;&nbsp;&nbsp;";
													}else{
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default\" />&nbsp;&nbsp;&nbsp;";
													}
												}
											}
					  tableactionTabContent +="</div>"
	                                    	+"</div>"
	                                    	+"</div>";
				}else{
					tableactionTabContent +="<div id=\"table-"+tableName+"-tab\" class=\"tab-pane fade \">"
	                    	+"<div class=\"row\">"
	                    	+"<div class=\"col-lg-12\">";
							for (int i = 0; i < tableNames.length; i++) {
								tableactionTabContent +="<input type=\"button\" data-value=\""+tableNames[i]+"\" value=\""+tableNames[i]+"\" class=\"btn btn-default \" />&nbsp;&nbsp;&nbsp;";
							}
	  tableactionTabContent +="</div>"
	                    	+"</div>"
	                    	+"</div>";
				}
			}
		}  
		//获取字段
		List<DataProperty> dataProperties = publicService.getDataProperty(classes);
	/*	//排序
		Collections.sort(dataProperties, new Comparator<DataProperty>() {
	      public int compare(DataProperty o1, DataProperty o2) {
	    	  	//按照sort进行升序排列  
                if(o1.getSort() > o2.getSort()){  
                    return 1;  
                }  
                if(o1.getSort() == o2.getSort()){  
                    return 0;  
                }  
                return -1;  
	      }
	    });*/
		String select="";
		for(DataProperty dp : dataProperties){ 
			if("1".equals(dp.getAdminListShow()) && request.getParameter(dp.getNameEn()) !=null && !"".equals(request.getParameter(dp.getNameEn()))){
				select += "&"+dp.getNameEn()+"="+request.getParameter(dp.getNameEn());
			}
		}
		if(createUserId !=null && !"".equals(createUserId)){
			select += "&createUserId="+createUserId;
		}
		if(curr !=null && !"".equals(curr)){
			select += "&curr="+curr;
		}
		if(startTime !=null && !"".equals(startTime)){
			select += "&startTime="+startTime;
		}
		if(endTime !=null && !"".equals(endTime)){
			select += "&endTime="+endTime;
		}
		if(status !=null && !"".equals(status)){
			select += "&status="+status;
		}
		List<LinkedHashMap<String, Object>> rightContent = new ArrayList<LinkedHashMap<String, Object>>();
		List<LinkedHashMap<String, Object>> seek = new ArrayList<LinkedHashMap<String, Object>>();
		HashMap<String, LinkedHashMap<String,String>> arrList = new HashMap<String, LinkedHashMap<String,String>>();
		//赛选项
		String filtrateContent = "";
		//是否启用工作流
		int workflowStatus = 0;
		boolean  isOpenWorkflow = false;
		HashMap<String, Object> queryWorkflowParams = new HashMap<String, Object>();
		queryWorkflowParams.put("=,classes_en", classesEn);
		List<Workflow> workflowList = publicService.getWorkflow(queryWorkflowParams, 1, 1);
		if(null != workflowList && workflowList.size()>0){
			workflowStatus = workflowList.get(0).getStatus();
			isOpenWorkflow=true;
		}
		
		List<String> nameEnList = new ArrayList<String>();
		for (DataProperty dp : dataProperties) {
			Integer dataTypeId= dp.getDataTypeId();
			DataType dataType = publicService.findDataType(dataTypeId);
			if ("1".equals(dp.getAdminListShow())) {
				LinkedHashMap<String, Object> catalogueList = new LinkedHashMap<String, Object>();
				catalogueList.put("nameZh", dp.getNameZh());
				catalogueList.put("nameEn",dp.getNameEn());
				catalogueList.put("dataType", dataType.getNameEn());
				if(dp.getDictId()!=0){
					Dict dict =publicService.findDict(dp.getDictId());
					catalogueList.put("type", dict.getDictType());
					catalogueList.put("typeId", dp.getDictId());
				}else{
					catalogueList.put("type", "0");
				}
				rightContent.add(catalogueList);
				seek.add(catalogueList);
				filtrateContent += dp.getNameEn()+",";
				nameEnList.add(dp.getNameEn());
				
				//字典
				if(dp.getDictId() != 0 && "1".equals(dp.getAdminListShow())){
					Dict dicts = publicService.findDict(dp.getDictId());
					List<DictItem> dictItem = publicService.getDictItem(dicts);
					LinkedHashMap<String,String> dictitemList = new LinkedHashMap<String, String>();
					for(DictItem dic : dictItem){
						dictitemList.put(dic.getValue(), dic.getNameZh());
					}
					arrList.put(dp.getNameEn(), dictitemList);
				}
			}
		}
		int iIme=0;
		String selecttext="<table style='width: 95%;margin-top: 40px;'>";
		for(int i=0;i<(int)Math.ceil(Double.valueOf(seek.size())/3);i++){
				int setime=0;
				selecttext +="<tr height='50'>";
				for(int j=iIme;j<seek.size();j++){
					setime ++;
					if(setime ==4){
						break;
					}
					iIme ++;
					LinkedHashMap<String, Object> getvalue =seek.get(j);
					selecttext +="<td align='right'>"+getvalue.get("nameZh")+"&nbsp;&nbsp;</td>";
						if(getvalue.get("type").toString().equals("1")){
							selecttext +="<td><select id='dictitemName_"+getvalue.get("nameEn")+"' class='form-control' style='width: 100%;' name='"+getvalue.get("nameEn")+"'><option selected='selected' value=''>请选择</option>";
							LinkedHashMap<String,String> arrListText =arrList.get(getvalue.get("nameEn"));
								 	for(String text:arrListText.keySet()){
								 		selecttext +="<option value="+text+">"+arrListText.get(text)+"</option>";
								 	}
							selecttext +="</select>";
						}
						if(getvalue.get("type").toString().equals("2")){
							selecttext +="<td><div class='input-group input-group-sm mbs' style='width: 100%;'>";
							selecttext +="<input id='dictitemName_"+getvalue.get("nameEn")+"'  name='dictitemName_"+getvalue.get("nameEn")+"' type='text' placeholder='请选择' class='form-control' disabled='true' onchange='selectOnchange()' /> ";
							selecttext +="<input id='dictitemId_"+getvalue.get("nameEn")+"'  name='"+getvalue.get("nameEn")+"' type='hidden'  class='form-control' /> ";
							selecttext +="<span class='input-group-btn'><button id='t_"+getvalue.get("nameEn")+"' onclick='saveEditZTree(\""+getvalue.get("typeId")+"\",\""+getvalue.get("nameEn")+"\")' type='button' data-toggle='dropdown' class='btn btn-success dropdown-toggle'>选择...</button></span>";
							selecttext +="</div>";
						}
						if(getvalue.get("type").toString().equals("0")){
							if("date_year".equals(getvalue.get("dataType"))){
								selecttext +="<td width='28%'>";
								selecttext +="<input type='text' class='form-control' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy\"})' style='width: 45%;display: inline-block;' id='dictitemName_"+getvalue.get("nameEn")+"_startTime' name='"+getvalue.get("nameEn")+"_startTime'/>";
								selecttext +="<span style='display: inline-block;width: 10%;text-align: center;'>至</span>";
								selecttext +="<input type='text' class='form-control' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy\"})' style='width: 45%;display: inline-block;' id='dictitemName_"+getvalue.get("nameEn")+"_endTime' name='"+getvalue.get("nameEn")+"_endTime' />";
							}else if("date_year_month".equals(getvalue.get("dataType"))){
								selecttext +="<td width='28%'>";
								selecttext +="<input type='text' class='form-control' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy-MM\"})' style='width: 45%;display: inline-block;' id='dictitemName_"+getvalue.get("nameEn")+"_startTime' name='"+getvalue.get("nameEn")+"_startTime'/>";
								selecttext +="<span style='display: inline-block;width: 10%;text-align: center;'>至</span>";
								selecttext +="<input type='text' class='form-control' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy-MM\"})' style='width: 45%;display: inline-block;' id='dictitemName_"+getvalue.get("nameEn")+"_endTime' name='"+getvalue.get("nameEn")+"_endTime' />";
							}else if("date_year_month_day".equals(getvalue.get("dataType"))){
								selecttext +="<td width='28%'>";
								selecttext +="<input type='text' class='form-control' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy-MM-dd\"})' style='width: 45%;display: inline-block;' id='dictitemName_"+getvalue.get("nameEn")+"_startTime' name='"+getvalue.get("nameEn")+"_startTime'/>";
								selecttext +="<span style='display: inline-block;width: 10%;text-align: center;'>至</span>";
								selecttext +="<input type='text' class='form-control' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy-MM-dd\"})' style='width: 45%;display: inline-block;' id='dictitemName_"+getvalue.get("nameEn")+"_endTime' name='"+getvalue.get("nameEn")+"_endTime' />";
							}else if("datetime".equals(getvalue.get("dataType"))){
								selecttext +="<td width='28%'>";
								selecttext +="<input type='text' class='form-control' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy-MM-dd HH:mm:ss\"})' style='width: 45%;display: inline-block;' id='dictitemName_"+getvalue.get("nameEn")+"_startTime' name='"+getvalue.get("nameEn")+"_startTime'/>";
								selecttext +="<span style='display: inline-block;width: 10%;text-align: center;'>至</span>";
								selecttext +="<input type='text' class='form-control' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy-MM-dd HH:mm:ss\"})' style='width: 45%;display: inline-block;' id='dictitemName_"+getvalue.get("nameEn")+"_endTime' name='"+getvalue.get("nameEn")+"_endTime' />";
							}else{
								selecttext +="<td><input type='text' class='form-control' onchange='selectOnchange()' style='width: 100%;' id='dictitemName_"+getvalue.get("nameEn")+"' name='"+getvalue.get("nameEn")+"' />";
							}
						}
						
					selecttext +="</td>";
				}
		}
		selecttext +="</tr>";
		selecttext +="<tr height='50'><td align='right'>创建人&nbsp;&nbsp;</td><td>";
		selecttext +="<select id='dictitemName_selectUser' class='form-control' style='width: 100%;' name='dictitemName_selectUser'><option selected='selected' value=''>请选择</option>";
		 	for (int j = 0; j < users.size(); j++) {
		 		User user=users.get(j);
		 		if(user.getId() != 1){
		 			selecttext +="<option value="+user.getId()+">"+user.getNickname()+"</option>";
		 		}
		 	}
		selecttext +="</select></td>";
		selecttext +="<td align='right'>开始时间&nbsp;&nbsp;</td><td>";
		selecttext +="<input type='text' onchange='selectOnchange()' class='form-control' style='width: 100%;float: right;' id='dictitemName_startTime' name='dictitemName_startTime' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy-MM-dd\"})'/></td>";
		selecttext +="<td align='right'>结束时间&nbsp;&nbsp;</td><td>";
		selecttext +="<input type='text' onchange='selectOnchange()' class='form-control' style='width: 100%; float: right;' id='dictitemName_endTime' name='dictitemName_endTime' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy-MM-dd\"})'/></td>";
		selecttext +="</tr>";
		if(isOpenWorkflow)
		{
		selecttext +="<tr  style='display: none;'><td align='right'>数据状态&nbsp;&nbsp;</td><td>";
		selecttext +="<select id='dictitemName_status' class='form-control' style='width: 100%;' name='dictitemName_status'>";
		selecttext +="<option value=''>请选择</option>";
		selecttext +="<option value='isnotnull'>正式库</option>";
		selecttext +="<option value='isnull' selected='selected'>草稿库</option>";
		selecttext +="</select></td>";
		selecttext +="</tr>";	
		}
		else
		{
		selecttext +="<tr style='display: none;'><td align='right'>状态&nbsp;&nbsp;</td><td>";
		selecttext +="<select id='dictitemName_status' class='form-control' style='width: 100%;' name='dictitemName_status'>";
		selecttext +="<option selected='selected' value=''>请选择</option>";
		selecttext +="<option value='0'>未通过</option>";
		selecttext +="<option value='1'>已通过</option>";
		selecttext +="</select></td>";
		selecttext +="</tr>";
		}
		/*selecttext +="<tr height='50'><td align='right'>关联开始时间&nbsp;&nbsp;</td><td>";
		selecttext +="<input type='text' class='form-control' style='width: 100%;float: right;' id='dictitemName_relevanceStartTime' name='dictitemName_relevanceStartTime' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy-MM-dd\"})'/></td>";
		selecttext +="<td align='right'>关联结束时间&nbsp;&nbsp;</td><td>";
		selecttext +="<input type='text' class='form-control' style='width: 100%; float: right;' id='dictitemName_relevanceEndtTime' name='dictitemName_relevanceEndtTime' onclick='WdatePicker({skin:\"whyGreen\",dateFmt:\"yyyy-MM-dd\"})'/></td>";
		selecttext +="</tr>";*/
		selecttext +="<tr height='50'>"
		        +"<td>&nbsp;</td><td colspan='6'><button type='button' data-toggle='dropdown'  onclick='demo1(1,0)' class='btn btn-success dropdown-toggle'>精确搜索</button>&nbsp;&nbsp;&nbsp;&nbsp;"
		        +"<button type='button' data-toggle='dropdown' onclick='demo1(1,1)' class='btn btn-success dropdown-toggle'>模糊搜索</button>&nbsp;&nbsp;&nbsp;&nbsp;"
		        +"<button type='button' data-toggle='dropdown' onclick='deleteselect()' class='bbtn btn-sm btn-primary'>清空筛选项</button>";
			if(classesEn.equals("ke_hu_zi_liao")){
				selecttext +="&nbsp;&nbsp;&nbsp;&nbsp;<button id='dispaliy' type='button' data-toggle='dropdown' onclick='operation()' class='btn btn-success dropdown-toggle'>批量操作客户级别</button>";
			}
		
		selecttext +="</td></tr>";

		selecttext +="</table>";
		//添加固定显示
		LinkedHashMap<String, Object> userList = new LinkedHashMap<String, Object>();
		userList.put("nameEn", "createUserId");
		userList.put("nameZh", "创建人");
		rightContent.add(userList);
		LinkedHashMap<String, Object> TimeList = new LinkedHashMap<String, Object>();
		TimeList.put("nameEn", "create_time");
		TimeList.put("nameZh", "创建时间");
		rightContent.add(TimeList);
		/*LinkedHashMap<String, Object> statusList = new LinkedHashMap<String, Object>();
		statusList.put("nameEn", "status");
		statusList.put("nameZh", "状态");
		rightContent.add(statusList);*/
		
		nameEnList.add("createUserId");
		nameEnList.add("createTime");
		ModelAndView view = new ModelAndView();
		view.addObject("classesEn", classesEn);
		view.addObject("classesId", classesId);
		view.addObject("pageNum", 1);
		view.addObject("headline", headline);
		view.addObject("describe", describe);
		view.addObject("catalogueList", rightContent);
		view.addObject("nameEnList", nameEnList);
		view.addObject("pagecount", count);
		view.addObject("records", records);
	//	view.addObject("pageCount", page);
		view.addObject("seek", seek);
		view.addObject("selectCount", (int)Math.ceil(Double.valueOf(seek.size())/3));
		view.addObject("arrList", arrList);
		view.addObject("selecttext", selecttext);
		view.addObject("filtrateContent", filtrateContent);
		view.addObject("screenContent", select);
		view.addObject("tableactionTabContent", tableactionTabContent);
		view.addObject("tableactiondTab", tableactiondTab);
		view.addObject("audit", audit);
		view.addObject("workflowStatus", workflowStatus);
		view.setViewName("/modules/repository/knowledge_edit_data_list");
		return view;
	}

	/**
	 * 知识加工-数据列表-AJAX
	 * zhongfeng
	 * 2016.9.12
	 */
	@RequestMapping("knowledge-edit-data-list-text.html")
	public void toKnowledgeEditDataListText(HttpServletRequest request,HttpServletResponse response) throws Exception {

		String classesEn = request.getParameter("classesEn");
		int classesId = Integer.parseInt(request.getParameter("classesId"));
		String pageNum = request.getParameter("page");
		String searchType = request.getParameter("searchType");
		String chartName = request.getParameter("chartName");
		String databaseName = request.getParameter("databaseName");
		
		Integer userid =(Integer) request.getSession().getAttribute("userid");
		User upUser =publicService.findUser(userid);
		String rebate = request.getParameter("screenContent");
	    JSONObject jb = JSONObject.fromObject(rebate);
	    String formalOrDraft=null;
	    Map map = (Map)jb;
	 
	    // 判断显示的列
 		//Classes classes = publicService.findClasses(classesId);
	    String SQLShow="";
 		List<DataProperty> getDataProperties = searchService.getDataPropertyListCache(classesEn);
 		List<DataProperty> dataProperties = new ArrayList<DataProperty>();
 		for (int i = 0; i < getDataProperties.size(); i++) {
 		   DataProperty aDataProperty = getDataProperties.get(i);
 		   if("1".equals(aDataProperty.getAdminListShow())){
 		      dataProperties.add(aDataProperty);
 		     SQLShow +=aDataProperty.getField()+",";
 		   }
        }
 		if(!"".equals(SQLShow)){
 		   SQLShow = SQLShow +"create_user_id,dictitemName_status";
 		}
		//筛选页数
		Cookie[] cookies = request.getCookies();
		String recordCount = null;
		if (cookies != null) {
			for (Cookie cookie : cookies) {
				if ("recordCount".equals(cookie.getName())) {
					recordCount = cookie.getValue(); // 得到筛选页数
				}
			
			}
		}
		int count=0;
		if(recordCount == null){
			count=15;
		}else{
			count=Integer.parseInt(recordCount);
		}
		 //获取服务器地址
		//上传	
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		//查询
		String adjunctPath =  XxlConfClient.get("dal.file.path", "");
		 
		int pageNumber;
		if (pageNum == "" || pageNum == null) {
			pageNumber = 1;
		} else {
			pageNumber = Integer.parseInt(pageNum);
		}
		// 得到存在那些值
		HashMap<String, Object> conditions = new HashMap<String, Object>();
		
		for (Object key : map.keySet()) {
			if("create_user_time".equals(key)&& !map.get(key).equals("#")){
				conditions.put("><create_time", map.get(key));
			}else if("relevance_time".equals(key)&& !map.get(key).equals("#")){
				//System.out.println(map.get(key));
			}else if("create_user_id".equals(key)&& !map.get(key).equals("#") &&!"".equals(map.get(key))){
				conditions.put("="+key.toString(), map.get(key));
			}else if("status".equals(key)&& !map.get(key).equals("#") &&!"".equals(map.get(key))){
			 if("isnotnull".equals(map.get(key).toString())){//正式库
					conditions.put("!Null,submit_time", map.get(key));
					formalOrDraft=map.get(key).toString();
				 }else if("isnull".equals(map.get(key).toString())){//草稿库
					conditions.put("Null,submit_time", map.get(key));	
					formalOrDraft=map.get(key).toString();
			  }else{
				conditions.put("="+key.toString(), map.get(key));
			}
			}else{
				if(!"".equals(map.get(key)) && !map.get(key).equals("#")){
					for (int i = 0; i < dataProperties.size(); i++) {
						DataProperty dataProperty = dataProperties.get(i);
						if(key.equals(dataProperty.getNameEn()) && dataProperty.getDictId() == 0){
							if("0".equals(searchType)){
								conditions.put("="+key.toString(), map.get(key));
							}else{
								if(dataProperty.getDataTypeId() == 10 || dataProperty.getDataTypeId()== 11 || dataProperty.getDataTypeId()== 12 || dataProperty.getDataTypeId()== 13){
									conditions.put("><"+key.toString(), map.get(key));
								}else{
									conditions.put(key.toString(), map.get(key));
								}
							}
						}
						if(key.equals(dataProperty.getNameEn()) && dataProperty.getDictId() != 0){
							if(20 == dataProperty.getDataTypeId()){
								if("0".equals(searchType)){
									conditions.put("="+key.toString(), map.get(key)+",");
								}else{
									conditions.put(key.toString(), map.get(key)+",");
								}
								conditions.put("!%"+key.toString(), "."+map.get(key));
							}else{
								conditions.put("="+key.toString(), map.get(key));
							}
						}
					}
				}
			}
		}
		
		List<Map<String,Object>> list=null;
		int page=1;
		long pageCount=0;
			
		if(userid == 1){
				//超级管理查询
				//list = dynamicService.getDynamicData(classesEn,conditions, pageNumber, count);
				if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
					list=dynamicService.getDynamicData(classesEn, conditions, "id", "desc", pageNumber, count,databaseName,chartName);
					//页数
					pageCount = dynamicService.getDynamicCount(classesEn, conditions,databaseName,chartName);
				}else{
					list=dynamicService.getDynamicData(classesEn, conditions, "id", "desc", pageNumber, count);
					//页数
					pageCount = dynamicService.getDynamicCount(classesEn, conditions);
				}
				
				page =(int)Math.ceil(Double.valueOf(pageCount)/count);
		}else{
			Integer departmentid =(Integer) request.getSession().getAttribute("departmentid");
			if(Integer.parseInt(upUser.getIsPrincipal().toString())!=1){
				//普通用户
				conditions.put("=create_user_id", userid);
			}else{
				//部门负责人
				conditions.put("=create_org_id", departmentid);
			}
			if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
				//list = dynamicService.getDynamicData(classesEn, conditions, pageNumber, count);
				list=dynamicService.getDynamicData(classesEn, conditions, "id", "desc", pageNumber, count,databaseName,chartName);
				pageCount = dynamicService.getDynamicCount(classesEn, conditions);
			}else{
				//list = dynamicService.getDynamicData(classesEn, conditions, pageNumber, count);
				list=dynamicService.getDynamicData(classesEn, conditions, "id", "desc", pageNumber, count);
				pageCount = dynamicService.getDynamicCount(classesEn, conditions);
			}
			
			page =(int)Math.ceil(Double.valueOf(pageCount)/count);
		}
		boolean isOpenWorkFlow=false; 
		//判断是否开启工作流
		HashMap<String, Object> queryWorkflowParams = new HashMap<String, Object>();
		queryWorkflowParams.put("=,classes_en", classesEn);
		List<Workflow> workflowList = publicService.getWorkflow(queryWorkflowParams, 1, 1);
		if(null != workflowList && workflowList.size()>0){
			isOpenWorkFlow=true;
		}
		// 得到显示内容
		List<Map<String, Object>> arraylist = new ArrayList<Map<String, Object>>();
			for (int i = 0; i < list.size(); i++) {
				Map<String, Object> hasmap = list.get(i);
				for(DataProperty dp : dataProperties){
					if(dp.getDataTypeId() == 8){
						if(hasmap.get(dp.getNameEn()) != null && !"".equals(hasmap.get(dp.getNameEn()))){
							String dizhi = "<img src='"+uploadPath+hasmap.get(dp.getNameEn())+"' onclick='querypho(\""+uploadPath+hasmap.get(dp.getNameEn())+"\")' width='30' height='30'/>";
							hasmap.put(dp.getNameEn(), dizhi);
						}else{
							hasmap.put(dp.getNameEn(), "");
						}
					}else if(dp.getDataTypeId() == 16 || dp.getDataTypeId() == 24|| dp.getDataTypeId() == 25){
					  //单个文件
						String wenjian = (String) hasmap.get(dp.getNameEn());
						if(wenjian != null){
							String [] wenjiansz =wenjian.split("%");
							String danwenjian = "";
							for (int j = 0; j < wenjiansz.length; j++) {
								if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
									danwenjian ="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
								}
							}
							hasmap.put(dp.getNameEn(), danwenjian);
						}
					}else if(dp.getDataTypeId() == 17){
					  //单多文件
						String wenjian = (String) hasmap.get(dp.getNameEn());
						if(wenjian != null){
							String [] wenjiansz =wenjian.split("%");
							String danwenjian = "";
							for (int j = 0; j < wenjiansz.length; j++) {
								if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
									danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
								}
							}
							hasmap.put(dp.getNameEn(), danwenjian);
						}
					}else if(dp.getDataTypeId() == 27){
						  //单多文件
							String wenjian = (String) hasmap.get(dp.getNameEn());
							if(wenjian != null){
								String [] wenjiansz =wenjian.split("∷");
								String danwenjian = "";
								for (int j = 0; j < wenjiansz.length; j++) {
									if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
										danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
									}
								}
								hasmap.put(dp.getNameEn(), danwenjian);
							}
					}else if(dp.getDataTypeId() == 26){
						String tupian = (String) hasmap.get(dp.getNameEn());
						if(tupian != null && !"".equals(tupian)){
							String [] tupiansz =tupian.split(";");
							String dantupian = "";
							for (int j = 0; j < tupiansz.length; j++) {
								if(tupiansz[j] != null && !"".equals(tupiansz[j])){
									dantupian +="<a href=javascript:querypho('"+uploadPath+tupiansz[j]+"') ><img src="+uploadPath+tupiansz[j]+" width='30' height='30'/></a>&nbsp;&nbsp;";
								}
							}
							hasmap.put(dp.getNameEn(), dantupian);
						}
					}else if(dp.getDataTypeId() == 5 || dp.getDataTypeId() == 6 ){
						String path = (String) hasmap.get(dp.getNameEn());
						if(path != null && !"".equals(path)){
							String url = CommonUrl.addPrefixPath("src", path, uploadPath);
							hasmap.put(dp.getNameEn(), url);
						}
					}
					Integer dictId=dp.getDictId();
					if(dictId != 0 && !"".equals(hasmap.get(dp.getNameEn()))&& hasmap.get(dp.getNameEn())!=null){
						
						HashMap<String, Object> queryParams = new HashMap<String, Object>();
						queryParams.put("=,value", hasmap.get(dp.getNameEn()));
						queryParams.put("=,dictId", dp.getDictId());
						List<DictItem> dictItem = publicService.getDictItem(queryParams, 1, 1);
							for(DictItem di: dictItem){
								hasmap.put(dp.getNameEn(), di.getNameZh());	
						}
						
						String multis = hasmap.get(dp.getNameEn()).toString();
						String multiname="";
						if(multis!=null && !"".equals(multis)){
							String [] multimap = multis.split(",");
							for (int k = 0; k < multimap.length; k++) {
								HashMap<String, Object> multiqueryParams = new LinkedHashMap<String, Object>();
								multiqueryParams.put("=,dict_id", dp.getDictId());
								multiqueryParams.put("=,value", multimap[k]);
								List<DictItem> aDictItems =publicService.getDictItem(multiqueryParams, 1, 1);
								if(aDictItems.size()>0){
									DictItem aDictItem=aDictItems.get(0);
									multiname += aDictItem.getNameZh()+",";
								}
							}
							if(!"".equals(multiname)){
								multiname = multiname.substring(0, multiname.length()-1);
								hasmap.put(dp.getNameEn(), multiname);
							}
						}
					}
                }
				//查询创建人
				if(hasmap.get("create_user_id")!=null && !hasmap.get("create_user_id").equals("")){
					String createUserId =  hasmap.get("create_user_id").toString();
					User user = publicService.findUser(Integer.parseInt(createUserId));
					
					if(null != user){
						hasmap.put("createUserId", user.getNickname());
						hasmap.put("username", upUser.getUsername());
					}else{
						hasmap.put("createUserId", "");
						hasmap.put("username", "");
					}
					
				}
				String status =  hasmap.get("status").toString();
			 if(isOpenWorkFlow){//开启了工作流则用工作流的状态
				 hasmap.put("status", "--");
			     String id = hasmap.get("id").toString();
			    /* HashMap<String, Object> WorkflowExecuteMap = new HashMap<String, Object>();
			     WorkflowExecuteMap.put("=,resource_id", id);
			     WorkflowExecuteMap.put("^,create_time", "desc");
				 List<WorkflowExecute> WorkflowExecuteList = publicService.getWorkflowExecute(WorkflowExecuteMap, 1, 1);
	             if(WorkflowExecuteList.size()>0){
	            	 Integer workflowNodeId = WorkflowExecuteList.get(0).getWorkflowNodeId();
	            	 WorkflowNode findWorkflowNode = publicService.findWorkflowNode(workflowNodeId);*/
	            /*	 if(null!=findWorkflowNode){
	            		 String nodeName = findWorkflowNode.getNodeName();
	            		 hasmap.put("status",nodeName); 
	            	 }*/
	               if("-1".equals(status)){
	            	   hasmap.put("status", "初稿");
	                }else if("0".equals(status)){
	 					hasmap.put("status", "未通过");
	 				}else if("1".equals(status)){
	 					hasmap.put("status", "已通过");
	 				}else if("2".equals(status)){
	 					hasmap.put("status", "审核中");
	 				}else if("3".equals(status)){
	 					hasmap.put("status", "编辑中");
	 				}else if("4".equals(status)){
	 					hasmap.put("status", "首次提交");
	 				}else if("5".equals(status)){
	 					hasmap.put("status", "重复提交");
	 				}else if("6".equals(status)){
	 					hasmap.put("status", "退回");
	 				}else if("7".equals(status)){
	 					hasmap.put("status", "下架");
	 				}
	 				
	               
	           /*  }*/
				}else{
				//查询状态
				if("0".equals(status)){
					hasmap.put("status", "未通过");
				}else if("1".equals(status)){
					hasmap.put("status", "已通过");
				}else if("2".equals(status)){
					hasmap.put("status", "审核中");
				}
				hasmap.put("statusType", status);
			}
				arraylist.add(hasmap);
		}
	
		HashMap<String, Object> hasmappage = new HashMap<String, Object>();
		hasmappage.put("pageCount", page);
		hasmappage.put("overallCount", pageCount);
		hasmappage.put("formalOrDraft", formalOrDraft);
		arraylist.add(hasmappage);
		String resultString = formatToJson(arraylist);
		super.pringWriterToPage(resultString, "application/json", response);
	}

/**
 * 客户资料验证
 * @author zf
 * 2017年3月8日16:38:22
 * 
 */
	@RequestMapping("verifyValue")
	public void verifyValue(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String classesEn = request.getParameter("classesEn");
		String value = request.getParameter("value");
		String key = request.getParameter("key");
		HashMap<String, Object> conditions = new HashMap<String, Object>();
		conditions.put("="+key, value);
		int count = dynamicService.getDynamicCount(classesEn, conditions).intValue();
		String resultString = formatToJson(count);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	
	
	/**
	 * @author zf
	 * 2017年3月14日18:14:04
	 * 发布
	 * @throws Exception 
	 */
	//全库
	@RequestMapping("knowledgeEditDataIssue")
	public void knowledgeEditDataIssue(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String classesEn = request.getParameter("classesEn");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");
		String userid = request.getSession().getAttribute("userid").toString();
		String updateTime = DateUtils.getDateTime();
		List<String> r = new ArrayList<String>();
    	String succeed ="";
		try {
			if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
				dynamicService.submitDynamicData(classesEn, updateTime, userid,databaseName,chartName);
			}else{
				//dynamicService.deleteIndexByClassesEn(classesEn);
				dynamicService.submitDynamicData(classesEn, updateTime, userid);
			}
			succeed= "yes";
			r.add(succeed);
		} catch (Exception e) {
			succeed = "no";
			r.add(succeed);
			e.printStackTrace();
		}
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	//单个
	@RequestMapping("knowledgeEditDataPublish")
	public void knowledgeEditDataPublish(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String classesEn = request.getParameter("classesEn");
		String id = request.getParameter("id");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");
		String userid = request.getSession().getAttribute("userid").toString();
		String updateTime = DateUtils.getDateTime();
		List<String> r = new ArrayList<String>();
		String succeed ="";
		try {
			if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
				dynamicService.submitDynamicData(classesEn, updateTime,userid,id,databaseName,chartName);
			}else{
				dynamicService.submitDynamicData(classesEn, updateTime,userid,id);
			}
			succeed= "yes";
			r.add(succeed);
		} catch (Exception e) {
			succeed = "no";
			r.add(succeed);
			e.printStackTrace();
		}
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	
	
	/**
	 * 知识加工-添加消息
	 * zhongfeng
	 * 2016.9.12
	 */
	
	@RequestMapping("show-edit-data-detail.html")
	public ModelAndView toKnowledgeEditDataClassDetail(HttpServletRequest request) {

		String classesEn = request.getParameter("classesEn");
		String subjectClassesEn = request.getParameter("subjectClassesEn");
		String idString = request.getParameter("idString");
		String clichId = request.getParameter("clichId");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");
		int classesId = Integer.parseInt(request.getParameter("classesId"));
		
		String rel = request.getParameter("rel");
		Classes classes = publicService.findClasses(classesId);
	
		String headline= classes.getNameZh();
		String describe = classes.getDescription();
	
		
		// 值
		List<DataProperty> dataProperties = publicService.getDataProperty(classes);
		
		//字典
		//List<DictItem> DictItem =new ArrayList<DictItem>();
		List<Map<String, Object>> arrList = new ArrayList<Map<String,Object>>();
		Map<Integer, Integer> dictsMap = new HashMap<Integer, Integer>();
		for(DataProperty dp : dataProperties){
			Integer dataTypeId= dp.getDataTypeId();
			if(null == dp.getFormValidationRegulation()){
				dp.setFormValidationRegulation("");
			}
			Integer dictId=dp.getDictId();
			if(dictId != 0){
				Dict dicts = publicService.findDict(dictId);
				dictsMap.put(dp.getDictId(), dicts.getDictType());
				Dict dict = new Dict();
				dict.setId(dictId);
				List<DictItem> dictItem = publicService.getDictItem(dict);
				for(DictItem dic : dictItem){
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("dpid", dp.getId());
					map.put("dicid", dic.getId());
					map.put("nameZh", dic.getNameZh());
					map.put("value", dic.getValue());
					arrList.add(map);
				}
				//dp.setDict(dicts);
			}
			//dp.setDataType(publicService.findDataType(dataTypeId));
		}
		
		//导航
		List<ObjectProperty> objectProperty = publicService.getObjectProperty(classes);
			for(ObjectProperty op :objectProperty){
				//op.setRelevanceClasses(publicService.findClasses(op.getRelevanceClassesId()));
			}
		
		//分库分表
		String tableactiondTab = "";
		String tableactionTabContent = "";
		String newsTab = "";
		String targetTableName = "";
		String targetDataSourceId = "";
		HashMap<String, Object> queryRepositoryCountParams = new HashMap<String, Object>();
		queryRepositoryCountParams.put("=,classes_en", classesEn);
		HashMap<String, Object> tableNameMap= new LinkedHashMap<String, Object>();
		List<ShardingRepositoryCount> ShardingRepositoryCountList = publicService.getShardingRepositoryCount(queryRepositoryCountParams, 1, publicService.getShardingRepositoryCountCount(queryRepositoryCountParams));
		for (int i = 0; i < ShardingRepositoryCountList.size(); i++) {
			ShardingRepositoryCount shardingRepositoryCount = ShardingRepositoryCountList.get(i);
			ShardingDataSource ShardingDataSource = publicService.findShardingDataSource(shardingRepositoryCount.getShardingDataSourceId());
			if(null == tableNameMap.get(ShardingDataSource.getNameEn()) || "".equals(tableNameMap.get(ShardingDataSource.getNameEn()))){
				int tepositoryCount = 0;
				for (int j = 0; j < ShardingRepositoryCountList.size(); j++) {
					ShardingRepositoryCount aShardingRepositoryCount= ShardingRepositoryCountList.get(j);
					if(aShardingRepositoryCount.getShardingDataSourceId().equals(shardingRepositoryCount.getShardingDataSourceId())){
						tepositoryCount = tepositoryCount + aShardingRepositoryCount.getDataCount();
					}
				}
				if(i == 0){
					newsTab = ShardingDataSource.getNameEn();
					targetDataSourceId = ShardingDataSource.getId().toString();
					tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle on\" value=\""+ShardingDataSource.getNameZh()+"（"+tepositoryCount+"）\" >&nbsp;&nbsp;&nbsp;";
				}else{
					tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle\" value=\""+ShardingDataSource.getNameZh()+"（"+tepositoryCount+"）\" >&nbsp;&nbsp;&nbsp;";
				}
			}
			if(null == tableNameMap.get(ShardingDataSource.getNameEn()) || "".equals(tableNameMap.get(ShardingDataSource.getNameEn()))){
				tableNameMap.put(ShardingDataSource.getNameEn(), shardingRepositoryCount.getTableName());
			}else{
				tableNameMap.put(ShardingDataSource.getNameEn(),tableNameMap.get(ShardingDataSource.getNameEn())+";"+shardingRepositoryCount.getTableName());
			}
		}
		for (String tableName : tableNameMap.keySet()) {
			Object oTableName = tableNameMap.get(tableName);
			if(null != oTableName && !"".equals(oTableName)){
				String [] tableNames = oTableName.toString().split(";");
				if(tableName.equals(newsTab)){
					tableactionTabContent +="<div id=\"table-"+tableName+"-tab\" class=\"tab-pane fade in active\">"
	                                    	+"<div class=\"row\">"
	                                    	+"<div class=\"col-lg-12\">";
											for (int i = 0; i < tableNames.length; i++) {
												if( i == 0){
													targetTableName = tableNames[i];
													tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default on\" />&nbsp;&nbsp;&nbsp;";
												}else{
													tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default\" />&nbsp;&nbsp;&nbsp;";
												}
											}
					  tableactionTabContent +="</div>"
	                                    	+"</div>"
	                                    	+"</div>";
				}else{
					tableactionTabContent +="<div id=\"table-"+tableName+"-tab\" class=\"tab-pane fade \">"
	                    	+"<div class=\"row\">"
	                    	+"<div class=\"col-lg-12\">";
							for (int i = 0; i < tableNames.length; i++) {
								tableactionTabContent +="<input type=\"button\" data-value=\""+tableNames[i]+"\" value=\""+tableNames[i]+"\" class=\"btn btn-default \" />&nbsp;&nbsp;&nbsp;";
							}
	  tableactionTabContent +="</div>"
	                    	+"</div>"
	                    	+"</div>";
				}
			}
		}  
		
		//获取服务器地址
		String serversPath =  XxlConfClient.get("dal.file.server", "") +"/";	
		ModelAndView view = new ModelAndView();
		view.addObject("classesEn", classesEn);
		view.addObject("classesId", classesId);
		view.addObject("headline", headline);
		view.addObject("describe", describe);
		//view.addObject("dict", DictItem);
		view.addObject("resultString", arrList);
		view.addObject("serversPath", serversPath);
		view.addObject("dictsMap", dictsMap);
		view.addObject("objectProperty", objectProperty);
		view.addObject("databaseName", databaseName);
		view.addObject("chartName", chartName);
		view.addObject("dataProperties", dataProperties);
		view.addObject("tableactiondTab", tableactiondTab);
		view.addObject("tableactionTabContent", tableactionTabContent);
		view.addObject("targetDataSourceId", targetDataSourceId);
		view.addObject("targetTableName", targetTableName);
		if(rel !=null){
			view.addObject("subjectClassesEn", subjectClassesEn);
			view.addObject("idString", idString);
			view.addObject("clichId", clichId);
			view.setViewName("/modules/repository/knowledge_edit_data_relevancedetail");
		}else{
			view.setViewName("/modules/repository/knowledge_edit_data_detail");
		}
		return view;
	}

	/**
	 * 知识加工-关联关系-ajax
	 * zhongfeng
	 * 2016.10.26
	 */
	@RequestMapping("queryrelevance")
	public void toKnowledgeEditDataClassRelevanceAjax(HttpServletRequest request,HttpServletResponse response) throws Exception {
		int relevanceid = Integer.parseInt(request.getParameter("id"));
		int clickId = Integer.parseInt(request.getParameter("clickId"));
		int classesId = Integer.parseInt(request.getParameter("classesId"));
		String pages =request.getParameter("page");
		String databaseId =request.getParameter("databaseId");
		String aTableName =request.getParameter("tableName");
		String seekVale =request.getParameter("seekVale");
		String[] selectIds =request.getParameterValues("value");
		/*String  filtrate =request.getParameter("filtrate");
		String  electText =request.getParameter("electText");*/
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		
		int pageNumber;
		if (pages == "") {
			pageNumber = 1;
		} else {
			pageNumber = Integer.parseInt(pages);
		}
		HashMap<String, Object> conditions = new HashMap<String, Object>();
		if(null != seekVale  && !"".equals(seekVale)){
			String keyValues[] = seekVale.split("≡");
			for (int i = 0; i < keyValues.length; i++) {
				conditions.put(keyValues[i].split("∷")[0], keyValues[i].split("∷")[1]);
			}
		}
		
		//获取服务器地址
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		//本类
		Classes classes = publicService.findClasses(classesId);
		//关联
		String[] relevances =null;
		Classes relevanceClasses = publicService.findClasses(relevanceid);
		List<DataProperty> dataProperties = publicService.getDataProperty(relevanceClasses);
		List<ObjectProperty> objectProperty =publicService.getObjectProperty(classes);
		
		
		/**
		 * 分库分表 start
		 */
		String tableactiondTab = "";
		String tableactionTabContent = "";
		String newsTab = "";
		String newstable = "";
		String shardingDataSourceId = "";
		HashMap<String, Object> queryRepositoryCountParams = new HashMap<String, Object>();
		queryRepositoryCountParams.put("=,classes_en", relevanceClasses.getNameEn());
		HashMap<String, Object> tableNameMap= new LinkedHashMap<String, Object>();
		List<ShardingRepositoryCount> ShardingRepositoryCountList = publicService.getShardingRepositoryCount(queryRepositoryCountParams, 1, publicService.getShardingRepositoryCountCount(queryRepositoryCountParams));
		for (int i = 0; i < ShardingRepositoryCountList.size(); i++) {
			ShardingRepositoryCount shardingRepositoryCount = ShardingRepositoryCountList.get(i);
			ShardingDataSource ShardingDataSource = publicService.findShardingDataSource(shardingRepositoryCount.getShardingDataSourceId());
			if(null == tableNameMap.get(ShardingDataSource.getNameEn()) || "".equals(tableNameMap.get(ShardingDataSource.getNameEn()))){
				int tepositoryCount = 0;
				for (int j = 0; j < ShardingRepositoryCountList.size(); j++) {
					ShardingRepositoryCount aShardingRepositoryCount= ShardingRepositoryCountList.get(j);
					if(aShardingRepositoryCount.getShardingDataSourceId().equals(shardingRepositoryCount.getShardingDataSourceId())){
						tepositoryCount = tepositoryCount + aShardingRepositoryCount.getDataCount();
					}
				}
				if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
					if(databaseId.equals(ShardingDataSource.getId().toString()) ){
						newsTab = ShardingDataSource.getNameEn();
						shardingDataSourceId = ShardingDataSource.getId().toString();
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle on\" value=\""+ShardingDataSource.getNameZh()+"（"+tepositoryCount+"）\" >&nbsp;&nbsp;&nbsp;";
					}else{
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle\" value=\""+ShardingDataSource.getNameZh()+"（"+tepositoryCount+"）\" >&nbsp;&nbsp;&nbsp;";
					}
				}else {
					if(i == 0){
						newsTab = ShardingDataSource.getNameEn();
						shardingDataSourceId = ShardingDataSource.getId().toString();
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle on\" value=\""+ShardingDataSource.getNameZh()+"（"+tepositoryCount+"）\" >&nbsp;&nbsp;&nbsp;";
					}else{
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle\" value=\""+ShardingDataSource.getNameZh()+"（"+tepositoryCount+"）\" >&nbsp;&nbsp;&nbsp;";
					}
				}
			}
			if(null == tableNameMap.get(ShardingDataSource.getNameEn()) || "".equals(tableNameMap.get(ShardingDataSource.getNameEn()))){
				tableNameMap.put(ShardingDataSource.getNameEn(), shardingRepositoryCount.getTableName());
			}else{
				tableNameMap.put(ShardingDataSource.getNameEn(),tableNameMap.get(ShardingDataSource.getNameEn())+";"+shardingRepositoryCount.getTableName());
			}
		}
		for (String tableName : tableNameMap.keySet()) {
			Object oTableName = tableNameMap.get(tableName);
			if(null != oTableName && !"".equals(oTableName)){
				String [] tableNames = oTableName.toString().split(";");
				if(tableName.equals(newsTab)){
					tableactionTabContent +="<div id=\"table-"+tableName+"-tab\" class=\"tab-pane fade in active\">"
	                                    	+"<div class=\"row\">"
	                                    	+"<div class=\"col-lg-12\">";
											for (int i = 0; i < tableNames.length; i++) {
												if(null != aTableName && !"".equals(aTableName)&& !"undefined".equals(aTableName)){
													if(aTableName.equals(tableNames[i])){
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default on\" />&nbsp;&nbsp;&nbsp;";
														newstable = tableNames[i];
													}else{
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default\" />&nbsp;&nbsp;&nbsp;";
													}
												}else{
													if( i == 0){
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default on\" />&nbsp;&nbsp;&nbsp;";
														newstable = tableNames[i];
													}else{
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default\" />&nbsp;&nbsp;&nbsp;";
													}
												}
											}
					  tableactionTabContent +="</div>"
	                                    	+"</div>"
	                                    	+"</div>";
				}else{
					tableactionTabContent +="<div id=\"table-"+tableName+"-tab\" class=\"tab-pane fade \">"
	                    	+"<div class=\"row\">"
	                    	+"<div class=\"col-lg-12\">";
							for (int i = 0; i < tableNames.length; i++) {
								tableactionTabContent +="<input type=\"button\" data-value=\""+tableNames[i]+"\" value=\""+tableNames[i]+"\" class=\"btn btn-default \" />&nbsp;&nbsp;&nbsp;";
							}
	  tableactionTabContent +="</div>"
	                    	+"</div>"
	                    	+"</div>";
				}
			}
		}  
			
			
		/**
		 * 分库分表 end
		 */
		
		Cookie[] cookies = request.getCookies();
		String editEelevanceCount="10";
		for (int i = 1; i < cookies.length; i++) {
			if("editEelevanceCount".equals(cookies[i].getName())){
				editEelevanceCount= cookies[i].getValue();
			}
		}
		//查询关联内容	
		int count ;
		long dynamicDataCount =0;
		List<Map<String,Object>> dynamicData;
		if(null != newsTab && !"".equals(newsTab)){
			if(null != seekVale  && !"".equals(seekVale)){
				dynamicData = dynamicService.getDynamicData(relevanceClasses.getNameEn(), conditions,pageNumber,Integer.parseInt(editEelevanceCount),shardingDataSourceId, newstable);
				dynamicDataCount =dynamicService.getDynamicCount(relevanceClasses.getNameEn(),conditions,shardingDataSourceId, newstable);
				count=(int)Math.ceil(Double.valueOf(dynamicDataCount)/Integer.parseInt(editEelevanceCount));
			}else{
				dynamicData=dynamicService.getDynamicData(relevanceClasses.getNameEn(), null, pageNumber,Integer.parseInt(editEelevanceCount) ,shardingDataSourceId, newstable);
				dynamicDataCount =dynamicService.getDynamicCount(relevanceClasses.getNameEn(), new HashMap<String, Object>() ,shardingDataSourceId, newstable);
				count = (int)Math.ceil(Double.valueOf(dynamicDataCount)/Integer.parseInt(editEelevanceCount));
			}
		}else{
			if(null != seekVale  && !"".equals(seekVale)){
				dynamicData = dynamicService.getDynamicData(relevanceClasses.getNameEn(), conditions,pageNumber,Integer.parseInt(editEelevanceCount) );
				dynamicDataCount =dynamicService.getDynamicCount(relevanceClasses.getNameEn(),conditions);
				count=(int)Math.ceil(Double.valueOf(dynamicDataCount)/Integer.parseInt(editEelevanceCount));
			}else{
				dynamicData=dynamicService.getDynamicData(relevanceClasses.getNameEn(), null, pageNumber,Integer.parseInt(editEelevanceCount) );
				dynamicDataCount =dynamicService.getDynamicCount(relevanceClasses.getNameEn(), null);
				count = (int)Math.ceil(Double.valueOf(dynamicDataCount)/Integer.parseInt(editEelevanceCount));
			}
		}
		
		//图片及字典
		List<DataType> dataType =publicService.getDataType();
		List<String> nameEnList = new ArrayList<String>();
		for (DataProperty dp : dataProperties) {
			if (dp.getAdminListShow().equals("1")) {
				nameEnList.add(dp.getNameEn());
				Integer dataTypeId= dp.getDataTypeId();
				//dp.setDataType(publicService.findDataType(dataTypeId));
			}
		}
		for (int i = 0; i < dynamicData.size(); i++) {
			Map<String, Object> hasmap = dynamicData.get(i);
			
			for(DataProperty dp : dataProperties){
				if(dp.getDataTypeId() != null && dp.getDataTypeId()== 8){
					if(hasmap.get(dp.getNameEn()) != null && !"".equals(hasmap.get(dp.getNameEn()))){
						String dizhi = "<img src='"+uploadPath+hasmap.get(dp.getNameEn())+"' onclick='queryphogl(\""+uploadPath+hasmap.get(dp.getNameEn())+"\")' width='30' height='30'/>";
						hasmap.put(dp.getNameEn(), dizhi);	
					}else{
						hasmap.put(dp.getNameEn(), "");	
					}
								
				}
				if(dp.getDataTypeId()== 16 || dp.getDataTypeId() == 24|| dp.getDataTypeId() == 25){
					String wenjian = (String) hasmap.get(dp.getNameEn());
					if(wenjian != null){
						String [] wenjiansz =wenjian.split("%");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						hasmap.put(dp.getNameEn(), danwenjian);
					}
				}
				if(dp.getDataTypeId() == 26){
					String tupian = (String) hasmap.get(dp.getNameEn());
					if(tupian != null && !"".equals(tupian)){
						String [] tupiansz =tupian.split(";");
						String dantupian = "";
						for (int j = 0; j < tupiansz.length; j++) {
							if(tupiansz[j] != null && !"".equals(tupiansz[j])){
								dantupian +="<a href=javascript:querypicture('"+uploadPath+tupiansz[j]+"') ><img src="+uploadPath+tupiansz[j]+" width='30' height='30'/></a>&nbsp;&nbsp;";
							}
						}
						hasmap.put(dp.getNameEn(), dantupian);
					}
				}
				if(dp.getDataTypeId() != null && dp.getDataTypeId()== 17 ){
					String wenjian = (String) hasmap.get(dp.getNameEn());
					if(wenjian != null){
						String [] wenjiansz =wenjian.split("%");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						hasmap.put(dp.getNameEn(), danwenjian);
					}
				}
				if(dp.getDataTypeId() != null && dp.getDataTypeId()== 27 ){
					String wenjian = (String) hasmap.get(dp.getNameEn());
					if(wenjian != null){
						String [] wenjiansz =wenjian.split("∷");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						hasmap.put(dp.getNameEn(), danwenjian);
					}
				}
				if(dp.getDataTypeId() == 5 || dp.getDataTypeId() == 6 ){
					String path = (String) hasmap.get(dp.getNameEn());
					if(path != null && !"".equals(path)){
						String url = CommonUrl.addPrefixPath("src", path, uploadPath);
						hasmap.put(dp.getNameEn(), url);
					}
				}
				Integer dictId=dp.getDictId();
				if(dictId != 0){
					Dict dict = new Dict();
					dict.setId(dictId);
					List<DictItem> dictItem = publicService.getDictItem(dict);
					for(DictItem di: dictItem){
						if(di.getValue() == hasmap.get(dp.getNameEn()) || di.getValue().equals(hasmap.get(dp.getNameEn()))){
							hasmap.put(dp.getNameEn(), di.getNameZh());	
						}
					}
					Object multis = hasmap.get(dp.getNameEn());
					String multiname="";
					if(multis!=null && !"".equals(multis)){
						String [] multimap = multis.toString().split(",");
						for (int k = 0; k < multimap.length; k++) {
							HashMap<String, Object> multiqueryParams = new LinkedHashMap<String, Object>();
							multiqueryParams.put("=,dict_id", dp.getDictId());
							multiqueryParams.put("=,value", multimap[k]);
							List<DictItem> aDictItems =publicService.getDictItem(multiqueryParams, 1, publicService.getDictItemCount(multiqueryParams));
							if(aDictItems.size()>0){
								DictItem aDictItem =aDictItems.get(0);
								multiname += aDictItem.getNameZh()+",";
							}
						}
						if(!"".equals(multiname) && multiname != null){
							multiname = multiname.substring(0, multiname.length()-1);
							hasmap.put(dp.getNameEn(), multiname);
						}
					}
					
				}
				Integer dataTypeId= dp.getDataTypeId();
				//dp.setDataType(publicService.findDataType(dataTypeId));
			}
			
			if(selectIds != null){
				int page=0;
				for (int j = 0; j < selectIds.length; j++) {
					if( hasmap.get("id").toString().equals(selectIds[j])&& page == 0 ){
						page=1;
					}
				}
				if(page ==0){
					dynamicData.remove(i);
				}
			}
		}
			for(ObjectProperty op :objectProperty){
				if(op.getId() == clickId){
					relevances=op.getRelevanceClassFields().split(",");
				}
			}
			if(relevances != null){
				for(DataProperty dp :dataProperties){
					for(int i=0;i<relevances.length;i++){
						mp = new LinkedHashMap<String, Object>();
						if(dp.getRelevanceClassShowField().equals("1") && dp.getId() == Integer.parseInt(relevances[i])){
							mp.put("titleZh", dp.getNameZh());
							mp.put("titleEn", dp.getNameEn());
							r.add(mp);
						}
					}
				}
			}
		
		/**
		 * 已有数据赛选项 start
		 */
		//List<DataProperty> dataProperties = publicService.getDataProperty(classes);
		String keys="";
		List<LinkedHashMap<String, Object>> seek = new ArrayList<LinkedHashMap<String, Object>>();
		HashMap<String, LinkedHashMap<String,String>> arrList = new HashMap<String, LinkedHashMap<String,String>>();
			for (DataProperty dp : dataProperties) {
					Integer dataTypeId= dp.getDataTypeId();
					DataType aDataType = publicService.findDataType(dataTypeId);
					if ("1".equals(dp.getAdminListShow())) {
						LinkedHashMap<String, Object> catalogueList = new LinkedHashMap<String, Object>();
						catalogueList.put("nameZh", dp.getNameZh());
						catalogueList.put("nameEn",dp.getNameEn());
						catalogueList.put("dataType", aDataType.getNameEn());
						if(dp.getDictId()!=0){
							Dict dict =publicService.findDict(dp.getDictId());
							catalogueList.put("type", dict.getDictType());
							catalogueList.put("typeId", dp.getDictId());
						}else{
							catalogueList.put("type", "0");
						}
						seek.add(catalogueList);
						keys += dp.getNameEn()+";";
						//字典
						if(dp.getDictId() != 0 && "1".equals(dp.getAdminListShow())){
							Dict dicts = publicService.findDict(dp.getDictId());
							List<DictItem> dictItem = publicService.getDictItem(dicts);
							LinkedHashMap<String,String> dictitemList = new LinkedHashMap<String, String>();
							for(DictItem dic : dictItem){
								dictitemList.put(dic.getValue(), dic.getNameZh());
							}
							arrList.put(dp.getNameEn(), dictitemList);
						}
					}
				}
			int iIme=0;
			String selecttext="<table style='width: 95%;'>";
				for(int i=0;i<(int)Math.ceil(Double.valueOf(seek.size())/3);i++){
						int setime=0;
						selecttext +="<tr height='50'>";
						for(int j=iIme;j<seek.size();j++){
							setime ++;
							if(setime ==4){
								break;
							}
							iIme ++;
							LinkedHashMap<String, Object> getvalue =seek.get(j);
								/*if(getvalue.get("type").toString().equals("1")){
									selecttext +="<select id='dictitemName_"+getvalue.get("nameEn")+"' class='form-control' style='width: 100%;' name='"+getvalue.get("nameEn")+"'><option selected='selected' value=''>请选择</option>";
									LinkedHashMap<String,String> arrListText =arrList.get(getvalue.get("nameEn"));
										 	for(String text:arrListText.keySet()){
										 		selecttext +="<option value="+text+">"+arrListText.get(text)+"</option>";
										 	}
									selecttext +="</select>";
								}*/
								if(getvalue.get("type").toString().equals("0")){
									selecttext +="<td align='right'>"+getvalue.get("nameZh")+"&nbsp;&nbsp;</td><td>";
									selecttext +="<input type='text' class='form-control' style='width: 100%;' id='dictitemName_"+getvalue.get("nameEn")+"' name='"+getvalue.get("nameEn")+"' />";
									selecttext +="</td>";
								}
						}
				}
			selecttext +="</tr></table>";
		
		/**
		 * end
		 */
			
			
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("counts", count);
		map.put("rlist", r);
		map.put("rmap", dynamicData);
		map.put("selecttext", selecttext);
		map.put("dynamicDataCount", dynamicDataCount);
		map.put("seek", keys);
		map.put("tableactiondTab", tableactiondTab);
		map.put("tableactionTabContent", tableactionTabContent);
		String resultString = formatToJson(map);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	/**
	 * 知识加工-是否为管理员
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("superAdmin")
	public void toKnowledgeEditDatasuperAdmin(HttpServletRequest request,HttpServletResponse response) throws Exception {
		Integer userid=(Integer) request.getSession().getAttribute("userid");
		String resultString = formatToJson(userid);
		super.pringWriterToPage(resultString, "application/json", response);
		
	}
	/**
	 * 知识加工-关联关系-编辑
	 * zhongfeng
	 * 2016.10.26
	 */
	@RequestMapping("editrelevance")
	public void toKnowledgeEditDataClassEditRelevanceAjax(HttpServletRequest request,HttpServletResponse response) throws Exception {
		//关联id
		int relevanceid = Integer.parseInt(request.getParameter("id"));
		//选择关联字段id
		Integer clickId = Integer.parseInt(request.getParameter("clickId"));
		//编辑字段id
		String idString = request.getParameter("idString");
		String classesId = request.getParameter("classesId");
		//勾选内容
		String[] selectIds =request.getParameterValues("value");
		//主体类英文名
		String classesnameEn = request.getParameter("classesEn");
	
		String pages =request.getParameter("page");
		String databaseId =request.getParameter("databaseId");//关联数据源
		String tableName =request.getParameter("tableName");//关联表名
		String principalDatabaseId =request.getParameter("principalDatabaseId");//主体数据源
		String principalTableName =request.getParameter("principalTableName");//主体表名
		//获取服务器地址
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		List<Map<String, Object>> text = new ArrayList<Map<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		
		//当前页数
		int pageNumber;
		if (pages == "") {
			pageNumber = 1;
		} else {
			pageNumber = Integer.parseInt(pages);
		}
		
		//时间
		String createTime = DateUtils.getDateTime();
		//保存人
		Integer departmentid =(Integer) request.getSession().getAttribute("userid");
		User user = publicService.findUser(departmentid);
		List<User> users = publicService.getUser();
		//获得关联类
		Classes relevanceClasses=publicService.findClasses(relevanceid);
		String relevanceClassesName=relevanceClasses.getNameEn();
		//本类
		Classes classes = publicService.findClasses(Integer.parseInt(classesId));
		List<DataProperty> dataProperties = publicService.getDataProperty(relevanceClasses);
		
		List<ObjectProperty> objectProperty =publicService.getObjectProperty(classes);
		//保存
		List<Map<String,Object>> dynamicObjectData = null;
		if(null != principalDatabaseId && !"".equals(principalDatabaseId)&& !"undefined".equals(principalDatabaseId)){
			if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
				if(selectIds != null){
					long much =dynamicService.getDynamicObjectDataCount(classesnameEn, idString,null, clickId,principalDatabaseId,principalTableName);
					int sum = (int)much;
					dynamicObjectData=dynamicService.getDynamicObjectData(classesnameEn, idString, null, clickId, pageNumber, sum,principalDatabaseId,principalTableName);
					for (int i = 0; i < selectIds.length; i++) {
						int page=0;
						for (int j = 0; j < dynamicObjectData.size(); j++) {
							Map<String, Object> relevancText=dynamicObjectData.get(j);
							//关联Id
							String relevancId =relevancText.get("target_data_id").toString();
							if(selectIds[i].equals(relevancId)){
								page=1;
							}
						}
						if(page == 0){
							int logTime = 0;
							try {
								dynamicService.saveDynamicObjectDataST(classesnameEn, idString, relevanceClassesName, selectIds[i], clickId, createTime,departmentid.toString(),principalDatabaseId,principalTableName, databaseId,tableName);
								/** 修改主表时间  开始*/
						    	Map<String,Object> dynamic =dynamicService.findDynamicData(classesnameEn, idString,principalDatabaseId,principalTableName);
								String upid = dynamic.get("id").toString();
								String upstatus = dynamic.get("status").toString();
								String upversion = dynamic.get("version").toString();
								dynamic.remove("update_time");
								dynamic.remove("update_user_id");
								String updateUserId = departmentid.toString();
								String updateTime = DateUtils.getDateTime();
								dynamicService.editDynamicData(classesnameEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid,principalDatabaseId,principalTableName);
								/** 修改主表时间 结束    */
							} catch (Exception e) {
								this.log(user.getId(), "knowledge_data", classesId, null, "【"+user.getNickname()+"】【新增】知识【"+classes.getNameZh()+"】库关联知识【"+relevanceClasses.getNameZh()+"】库ID为【"+selectIds[i]+"】的数据失败！请检查数据是否正确！", 1);
								logTime=1;
								e.printStackTrace();
							}
							if(logTime==0){
								this.log(user.getId(), "knowledge_data", classesId, idString, "【"+user.getNickname()+"】【新增】知识【"+classes.getNameZh()+"】库关联知识【"+relevanceClasses.getNameZh()+"】库ID为【"+selectIds[i]+"】的数据成功！", 0);
							}
						}
					}
				}
			}else{
				if(selectIds != null){
					long much =dynamicService.getDynamicObjectDataCount(classesnameEn, idString,null, clickId,principalDatabaseId,principalTableName);
					int sum = (int)much;
					dynamicObjectData=dynamicService.getDynamicObjectData(classesnameEn, idString, null, clickId, pageNumber, sum,principalDatabaseId,principalTableName);
					for (int i = 0; i < selectIds.length; i++) {
						int page=0;
						for (int j = 0; j < dynamicObjectData.size(); j++) {
							Map<String, Object> relevancText=dynamicObjectData.get(j);
							//关联Id
							String relevancId =relevancText.get("target_data_id").toString();
							if(selectIds[i].equals(relevancId)){
								page=1;
							}
						}
						if(page == 0){
							int logTime = 0;
							try {
								dynamicService.saveDynamicObjectDataS(classesnameEn, idString, relevanceClassesName, selectIds[i], clickId, createTime,departmentid.toString(),principalDatabaseId,principalTableName);
								/** 修改主表时间  开始*/
						    	Map<String,Object> dynamic =dynamicService.findDynamicData(classesnameEn, idString,principalDatabaseId,principalTableName);
								String upid = dynamic.get("id").toString();
								String upstatus = dynamic.get("status").toString();
								String upversion = dynamic.get("version").toString();
								dynamic.remove("update_time");
								dynamic.remove("update_user_id");
								String updateUserId = departmentid.toString();
								String updateTime = DateUtils.getDateTime();
								dynamicService.editDynamicData(classesnameEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid,principalDatabaseId,principalTableName);
								/** 修改主表时间 结束    */
							} catch (Exception e) {
								this.log(user.getId(), "knowledge_data", classesId, null, "【"+user.getNickname()+"】【新增】知识【"+classes.getNameZh()+"】库关联知识【"+relevanceClasses.getNameZh()+"】库ID为【"+selectIds[i]+"】的数据失败！请检查数据是否正确！", 1);
								logTime=1;
								e.printStackTrace();
							}
							if(logTime==0){
								this.log(user.getId(), "knowledge_data", classesId, idString, "【"+user.getNickname()+"】【新增】知识【"+classes.getNameZh()+"】库关联知识【"+relevanceClasses.getNameZh()+"】库ID为【"+selectIds[i]+"】的数据成功！", 0);
							}
						}
					}
				}
			}
		}else{
			if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
				if(selectIds != null){
					long much =dynamicService.getDynamicObjectDataCount(classesnameEn, idString,null, clickId);
					int sum = (int)much;
					dynamicObjectData=dynamicService.getDynamicObjectData(classesnameEn, idString, null, clickId, pageNumber, sum);
					for (int i = 0; i < selectIds.length; i++) {
						int page=0;
						for (int j = 0; j < dynamicObjectData.size(); j++) {
							Map<String, Object> relevancText=dynamicObjectData.get(j);
							//关联Id
							String relevancId =relevancText.get("target_data_id").toString();
							if(selectIds[i].equals(relevancId)){
								page=1;
							}
						}
						if(page == 0){
							int logTime = 0;
							try {
								dynamicService.saveDynamicObjectDataT(classesnameEn, idString, relevanceClassesName, selectIds[i], clickId, createTime,departmentid.toString(),databaseId,tableName);
								/** 修改主表时间  开始*/
						    	Map<String,Object> dynamic =dynamicService.findDynamicData(classesnameEn, idString);
								String upid = dynamic.get("id").toString();
								String upstatus = dynamic.get("status").toString();
								String upversion = dynamic.get("version").toString();
								dynamic.remove("update_time");
								dynamic.remove("update_user_id");
								String updateUserId = departmentid.toString();
								String updateTime = DateUtils.getDateTime();
								dynamicService.editDynamicData(classesnameEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid);
								/** 修改主表时间 结束    */
							} catch (Exception e) {
								this.log(user.getId(), "knowledge_data", classesId, null, "【"+user.getNickname()+"】【新增】知识【"+classes.getNameZh()+"】库关联知识【"+relevanceClasses.getNameZh()+"】库ID为【"+selectIds[i]+"】的数据失败！请检查数据是否正确！", 1);
								logTime=1;
								e.printStackTrace();
							}
							if(logTime==0){
								this.log(user.getId(), "knowledge_data", classesId, idString, "【"+user.getNickname()+"】【新增】知识【"+classes.getNameZh()+"】库关联知识【"+relevanceClasses.getNameZh()+"】库ID为【"+selectIds[i]+"】的数据成功！", 0);
							}
						}
					}
				}
			}else{
				if(selectIds != null){
					long much =dynamicService.getDynamicObjectDataCount(classesnameEn, idString,null, clickId);
					int sum = (int)much;
					dynamicObjectData=dynamicService.getDynamicObjectData(classesnameEn, idString, null, clickId, pageNumber, sum);
					for (int i = 0; i < selectIds.length; i++) {
						int page=0;
						for (int j = 0; j < dynamicObjectData.size(); j++) {
							Map<String, Object> relevancText=dynamicObjectData.get(j);
							//关联Id
							String relevancId =relevancText.get("target_data_id").toString();
							if(selectIds[i].equals(relevancId)){
								page=1;
							}
						}
						if(page == 0){
							int logTime = 0;
							try {
								dynamicService.saveDynamicObjectData(classesnameEn, idString, relevanceClassesName, selectIds[i], clickId, createTime,departmentid.toString());
								/** 修改主表时间  开始*/
						    	Map<String,Object> dynamic =dynamicService.findDynamicData(classesnameEn, idString);
								String upid = dynamic.get("id").toString();
								String upstatus = dynamic.get("status").toString();
								String upversion = dynamic.get("version").toString();
								dynamic.remove("update_time");
								dynamic.remove("update_user_id");
								String updateUserId = departmentid.toString();
								String updateTime = DateUtils.getDateTime();
								dynamicService.editDynamicData(classesnameEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid);
								/** 修改主表时间 结束    */
							} catch (Exception e) {
								this.log(user.getId(), "knowledge_data", classesId, null, "【"+user.getNickname()+"】【新增】知识【"+classes.getNameZh()+"】库关联知识【"+relevanceClasses.getNameZh()+"】库ID为【"+selectIds[i]+"】的数据失败！请检查数据是否正确！", 1);
								logTime=1;
								e.printStackTrace();
							}
							if(logTime==0){
								this.log(user.getId(), "knowledge_data", classesId, idString, "【"+user.getNickname()+"】【新增】知识【"+classes.getNameZh()+"】库关联知识【"+relevanceClasses.getNameZh()+"】库ID为【"+selectIds[i]+"】的数据成功！", 0);
							}
						}
					}
				}
			}
		}
		//页数
		int count =0;
		HashMap<String, Object> queryParamsUser = new HashMap<String, Object>();
		queryParamsUser.put("=,userId",  user.getId());
		List<UserRole> userRole = publicService.getUserRole(queryParamsUser);
		String roleName="";
		if(userRole != null && userRole.size()>0){
			roleName = publicService.findRole(userRole.get(0).getRoleId()).getName();
		}
		
		if(null != principalDatabaseId && !"".equals(principalDatabaseId)&& !"undefined".equals(principalDatabaseId)){
			if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
				dynamicObjectData=dynamicService.getDynamicObjectData(classesnameEn, idString, null,clickId, pageNumber, 15,principalDatabaseId,principalTableName);
				long much =dynamicService.getDynamicObjectDataCount(classesnameEn, idString, null,clickId,principalDatabaseId,principalTableName);
				count=(int)Math.ceil(Double.valueOf(much)/15);
			}else{
				dynamicObjectData=dynamicService.getDynamicObjectData(classesnameEn, idString, null,clickId, pageNumber, 15,principalDatabaseId,principalTableName);
				long much =dynamicService.getDynamicObjectDataCount(classesnameEn, idString, null,clickId,principalDatabaseId,principalTableName);
				count=(int)Math.ceil(Double.valueOf(much)/15);
			}
		}else{
			dynamicObjectData=dynamicService.getDynamicObjectData(classesnameEn, idString, null,clickId, pageNumber, 15);
			long much =dynamicService.getDynamicObjectDataCount(classesnameEn, idString, null,clickId);
			count=(int)Math.ceil(Double.valueOf(much)/15);
		}
		//查询关联内容	
		/*
		long dynamicDataCount =dynamicService.getDynamicCount(relevanceClasses.getNameEn(), null);
		int dynamicDatas = (int)dynamicDataCount;
		List<Map<String,Object>> dynamicData=dynamicService.getDynamicData(relevanceClasses.getNameEn(), null, 1,dynamicDatas );*/
		
		
		List<String> nameEnList = new ArrayList<String>();
		//List<DataType> dataType =publicService.getDataType();
		for (DataProperty dp : dataProperties) {
			if (dp.getAdminListShow().equals("1")) {
				nameEnList.add(dp.getNameEn());
				//Integer dataTypeId= dp.getDataTypeId();
				//dp.setDataType(publicService.findDataType(dataTypeId));
			}
		}
		for (int i = 0; i < dynamicObjectData.size(); i++) {
			Map<String, Object> relevancText=dynamicObjectData.get(i);
			//关联Id
			Map<String, Object> hasmap = null;
			String relevancId =relevancText.get("target_data_id").toString();
			String reateUserId =relevancText.get("create_user_id").toString();
			Object targetShardingDataSourceId =relevancText.get("target_sharding_data_source_id");
			Object targetTableName =relevancText.get("target_table_name");
			if(null != targetShardingDataSourceId && !"".equals(targetShardingDataSourceId)&& !"undefined".equals(targetShardingDataSourceId)){
					if("ke_hu_zi_liao".equals(classesnameEn)){
						if("超级管理员".equals(roleName)){
							hasmap = dynamicService.findDynamicData(relevanceClasses.getNameEn(), relevancId,targetShardingDataSourceId.toString(),targetTableName.toString());
						}else{
							if(user.getId() == Integer.parseInt(reateUserId)){
								hasmap = dynamicService.findDynamicData(relevanceClasses.getNameEn(), relevancId,targetShardingDataSourceId.toString(),targetTableName.toString());
							}
						}
					}else{
						hasmap = dynamicService.findDynamicData(relevanceClasses.getNameEn(), relevancId,targetShardingDataSourceId.toString(),targetTableName.toString());
					}
			}else{
				if("ke_hu_zi_liao".equals(classesnameEn)){
					if("超级管理员".equals(roleName)){
						hasmap = dynamicService.findDynamicData(relevanceClasses.getNameEn(), relevancId);
					}else{
						if(user.getId() == Integer.parseInt(reateUserId)){
							hasmap = dynamicService.findDynamicData(relevanceClasses.getNameEn(), relevancId);
						}
					}
				}else{
					hasmap = dynamicService.findDynamicData(relevanceClasses.getNameEn(), relevancId);
				}
			}
			
			if(null != hasmap && hasmap.size()>0){
			
				/*for (int k = 0; k < users.size(); k++) {
					User u =users.get(k);
					if(hasmap.get("create_user_id").equals(u.getId().toString())){
						hasmap.put("createUserId", u.getNickname());
					}
				}*/
				if(null != hasmap.get("create_user_id") && !"".equals(hasmap.get("create_user_id"))){
					User u = publicService.findUser(Integer.parseInt(hasmap.get("create_user_id").toString()));
					if(null != u){
						hasmap.put("createUserId", u.getNickname());
					}else{
						hasmap.put("createUserId", "");
					}
				}
				
				hasmap.put("deleteId", relevancText.get("id"));
				for(DataProperty dp : dataProperties){
					if(dp.getDataTypeId() != null && dp.getDataTypeId() == 8){
						if(hasmap.get(dp.getNameEn()) != null && !"".equals(hasmap.get(dp.getNameEn()))){
							String dizhi = "<img src='"+uploadPath+hasmap.get(dp.getNameEn())+"' onclick='queryrelevancepicture(\""+uploadPath+hasmap.get(dp.getNameEn())+"\")' width='30' height='30'/>";
							hasmap.put(dp.getNameEn(), dizhi);				
						}else{
							hasmap.put(dp.getNameEn(), "");	
						}
					}
					if(dp.getDataTypeId() == 16 || dp.getDataTypeId() == 24|| dp.getDataTypeId() == 25){
						String wenjian = (String) hasmap.get(dp.getNameEn());
						if(wenjian != null){
							String [] wenjiansz =wenjian.split("%");
							String danwenjian = "";
							for (int y = 0; y < wenjiansz.length; y++) {
								if(wenjiansz[y] != null && !"".equals(wenjiansz[y])){
									danwenjian +="<a href="+uploadPath+wenjiansz[y]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
								}
							}
							hasmap.put(dp.getNameEn(), danwenjian);
						}
					}
					if(dp.getDataTypeId() == 26){
						String tupian = (String) hasmap.get(dp.getNameEn());
						if(tupian != null && !"".equals(tupian)){
							String [] tupiansz =tupian.split(";");
							String dantupian = "";
							for (int j = 0; j < tupiansz.length; j++) {
								if(tupiansz[j] != null && !"".equals(tupiansz[j])){
									dantupian +="<a href=javascript:querypicture('"+uploadPath+tupiansz[j]+"') ><img src="+uploadPath+tupiansz[j]+" width='30' height='30'/></a>&nbsp;&nbsp;";
								}
							}
							hasmap.put(dp.getNameEn(), dantupian);
						}
					}
					if(dp.getDataTypeId() != null && dp.getDataTypeId()== 17){
						String wenjian = (String) hasmap.get(dp.getNameEn());
						if(wenjian != null){
							String [] wenjiansz =wenjian.split("%");
							String danwenjian = "";
							for (int k = 0; k < wenjiansz.length; k++) {
								if(wenjiansz[k] != null && !"".equals(wenjiansz[k])){
									danwenjian +="<a href="+uploadPath+wenjiansz[k]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
								}
							}
							hasmap.put(dp.getNameEn(), danwenjian);
						}
					}
					if(dp.getDataTypeId() != null && dp.getDataTypeId()== 27){
						String wenjian = (String) hasmap.get(dp.getNameEn());
						if(wenjian != null){
							String [] wenjiansz =wenjian.split("∷");
							String danwenjian = "";
							for (int k = 0; k < wenjiansz.length; k++) {
								if(wenjiansz[k] != null && !"".equals(wenjiansz[k])){
									danwenjian +="<a href="+uploadPath+wenjiansz[k]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
								}
							}
							hasmap.put(dp.getNameEn(), danwenjian);
						}
					}
					if(dp.getDataTypeId() == 5 || dp.getDataTypeId() == 6 ){
						String path = (String) hasmap.get(dp.getNameEn());
						if(path != null && !"".equals(path)){
							String url = CommonUrl.addPrefixPath("src", path, uploadPath);
							hasmap.put(dp.getNameEn(), url);
						}
					}
					Integer dictId=dp.getDictId();
					if(dictId != 0){
						Dict dict = new Dict();
						dict.setId(dictId);
						List<DictItem> dictItem = publicService.getDictItem(dict);
						for(DictItem di: dictItem){
							if(di.getValue() == hasmap.get(dp.getNameEn()) || di.getValue().equals(hasmap.get(dp.getNameEn()))){
								hasmap.put(dp.getNameEn(), di.getNameZh());	
							}
						}
						
						String multis = hasmap.get(dp.getNameEn()).toString();
						String multiname="";
						if(multis!=null && !"".equals(multis)){
							String [] multimap = multis.split(",");
							for (int k = 0; k < multimap.length; k++) {
								HashMap<String, Object> multiqueryParams = new LinkedHashMap<String, Object>();
								multiqueryParams.put("=,dict_id", dp.getDictId());
								multiqueryParams.put("=,value", multimap[k]);
								List<DictItem> aDictItems =publicService.getDictItem(multiqueryParams, 1, publicService.getDictItemCount(multiqueryParams));
								if(aDictItems.size()>0){
									DictItem aDictItem =aDictItems.get(0);
									multiname += aDictItem.getNameZh()+",";
								}
							}
							if(!"".equals(multiname) && multiname != null){
								multiname = multiname.substring(0, multiname.length()-1);
								hasmap.put(dp.getNameEn(), multiname);
							}
						}
					}
					Integer dataTypeId= dp.getDataTypeId();
					//dp.setDataType(publicService.findDataType(dataTypeId));
				}
				hasmap.put("createTime", hasmap.get("create_time")+"（"+DateWeek.dateWeek(hasmap.get("create_time").toString())+"）");
				hasmap.put("targetShardingDataSourceId", targetShardingDataSourceId);
				hasmap.put("targetTableName", targetTableName);
				text.add(hasmap);
			}
		}
		String[] relevances=null;
		for(ObjectProperty op :objectProperty){
			if(op.getId() == clickId){
				relevances=op.getRelevanceClassFields().split(",");
			}
		}
		if(relevances != null){
			for(DataProperty dp :dataProperties){
				for(int i=0;i<relevances.length;i++){
					mp = new LinkedHashMap<String, Object>();
					if(dp.getRelevanceClassShowField().equals("1") && dp.getId() == Integer.parseInt(relevances[i])){
						mp.put("titleZh", dp.getNameZh());
						mp.put("titleEn", dp.getNameEn());
						r.add(mp);
					}
				}
			}
		}
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("counts", count);
		map.put("rlist", r);
		map.put("rmap", text);
		String resultString = formatToJson(map);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	
	
	
	
	/**
	 * 知识加工-关联关系-删除
	 * zhongfeng
	 * 2016.10.26
	 */
	@RequestMapping("deleterelevance")
	public void toKnowledgeDeleteDataClassEditRelevanceAjax(HttpServletRequest request,HttpServletResponse response) throws Exception {
		//关联id
		String relevanceid = request.getParameter("id");
		//选择关联字段id
		Integer clickId = Integer.parseInt(request.getParameter("clickId"));
		//编辑字段id
		String idString = request.getParameter("idString");
		String classesId = request.getParameter("classesId");
		//主体类英文名
		String classesnameEn = request.getParameter("classesEn");
		//删除id
		String deleteid = request.getParameter("deleteid");
		String databaseId = request.getParameter("databaseId");
		String tableName = request.getParameter("tableName");
		
		Classes clases=publicService.findClasses(Integer.parseInt(relevanceid));
		Classes hostclases=publicService.findClasses(Integer.parseInt(classesId));
		
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		Integer departmentid =(Integer) request.getSession().getAttribute("userid");
		int logTime=0;
		try {
			if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
				dynamicService.deleteDynamicObjectData(classesnameEn, deleteid, clickId,databaseId,tableName);
				/** 修改主表时间  开始*/
		    	Map<String,Object> dynamic =dynamicService.findDynamicData(classesnameEn, idString,databaseId,tableName);
				String upid = dynamic.get("id").toString();
				String upstatus = dynamic.get("status").toString();
				String upversion = dynamic.get("version").toString();
				dynamic.remove("update_time");
				dynamic.remove("update_user_id");
				String updateUserId = departmentid.toString();
				String updateTime = DateUtils.getDateTime();
				dynamicService.editDynamicData(classesnameEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid,databaseId,tableName);
				/** 修改主表时间 结束    */
			}else{
				dynamicService.deleteDynamicObjectData(classesnameEn, deleteid, clickId);
				/** 修改主表时间  开始*/
		    	Map<String,Object> dynamic =dynamicService.findDynamicData(classesnameEn, idString);
				String upid = dynamic.get("id").toString();
				String upstatus = dynamic.get("status").toString();
				String upversion = dynamic.get("version").toString();
				dynamic.remove("update_time");
				dynamic.remove("update_user_id");
				String updateUserId = departmentid.toString();
				String updateTime = DateUtils.getDateTime();
				dynamicService.editDynamicData(classesnameEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid);
				/** 修改主表时间 结束    */
			}
		} catch (Exception e) {
			this.log(user.getId(), "knowledge_data", classesId, deleteid, "【"+user.getNickname()+"】【删除】知识【"+hostclases.getNameZh()+"】库关联知识【"+clases.getNameZh()+"】库ID为【"+deleteid+"】的数据失败！请检查数据是否正确！", 1);
			logTime=1;
			e.printStackTrace();
		}
		if(logTime==0){
			this.log(user.getId(), "knowledge_data", classesId, deleteid, "【"+user.getNickname()+"】【删除】知识【"+hostclases.getNameZh()+"】库关联知识【"+clases.getNameZh()+"】库ID为【"+deleteid+"】的数据成功！", 0);
		}
		
		String resultString = formatToJson(1);
		super.pringWriterToPage(resultString, "application/json", response);
		
	}
	/**
	 * 知识加工-关联关系-删除全部
	 * zhongfeng
	 * 2016.10.26
	 */
	@RequestMapping("deleterelevanceAll")
	public void deleterelevanceAll(HttpServletRequest request,HttpServletResponse response) throws Exception {
		//关联id
		String relevanceid = request.getParameter("id");
		//选择关联字段id
		Integer clickId = Integer.parseInt(request.getParameter("clickId"));
		//编辑字段id
		String idString = request.getParameter("idString");
		String classesId = request.getParameter("classesId");
		//主体类英文名
		String classesnameEn = request.getParameter("classesEn");
		//勾选内容
		String[] selectIds =request.getParameterValues("deleteids");
		
		String databaseId = request.getParameter("databaseId");
		String tableName = request.getParameter("tableName");
		
		Classes clases=publicService.findClasses(Integer.parseInt(relevanceid));
		Classes hostclases=publicService.findClasses(Integer.parseInt(classesId));
		
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		Integer departmentid =(Integer) request.getSession().getAttribute("userid");
		int logTime=0;
		for (int i = 0; i < selectIds.length; i++) {
			try {
				if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
					dynamicService.deleteDynamicObjectData(classesnameEn, selectIds[i], clickId,databaseId,tableName);
				}else{
					dynamicService.deleteDynamicObjectData(classesnameEn, selectIds[i], clickId);
				}
			} catch (Exception e) {
				this.log(user.getId(), "knowledge_data", classesId, selectIds[i], "【"+user.getNickname()+"】【删除】知识【"+hostclases.getNameZh()+"】库关联知识【"+clases.getNameZh()+"】库ID为【"+selectIds[i]+"】的数据失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "knowledge_data", classesId, selectIds[i], "【"+user.getNickname()+"】【删除】知识【"+hostclases.getNameZh()+"】库关联知识【"+clases.getNameZh()+"】库ID为【"+selectIds[i]+"】的数据成功！", 0);
			}
		}
		if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
			/** 修改主表时间  开始*/
			Map<String,Object> dynamic =dynamicService.findDynamicData(classesnameEn, idString,databaseId,tableName);
			String upid = dynamic.get("id").toString();
			String upstatus = dynamic.get("status").toString();
			String upversion = dynamic.get("version").toString();
			dynamic.remove("update_time");
			dynamic.remove("update_user_id");
			String updateUserId = departmentid.toString();
			String updateTime = DateUtils.getDateTime();
			dynamicService.editDynamicData(classesnameEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid,databaseId,tableName);
			/** 修改主表时间 结束    */
		}else{
			/** 修改主表时间  开始*/
			Map<String,Object> dynamic =dynamicService.findDynamicData(classesnameEn, idString);
			String upid = dynamic.get("id").toString();
			String upstatus = dynamic.get("status").toString();
			String upversion = dynamic.get("version").toString();
			dynamic.remove("update_time");
			dynamic.remove("update_user_id");
			String updateUserId = departmentid.toString();
			String updateTime = DateUtils.getDateTime();
			dynamicService.editDynamicData(classesnameEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid);
			/** 修改主表时间 结束    */
		}
		String resultString = formatToJson(1);
		super.pringWriterToPage(resultString, "application/json", response);
		
	}

	/**
	 * 知识加工-关联关系-保存
	 * zhongfeng
	 * 2016.9.12
	 */
	
	@RequestMapping("addrelevance")
	@ResponseBody
	public void toKnowledgeEditDataAddRelevance(HttpServletRequest request,HttpServletResponse response)throws Exception {
		// 三级。如矿石等
		String classesEn = request.getParameter("classesEn");
		String classesId = request.getParameter("classesId");
		String subjectClassesEn = request.getParameter("subjectClassesEn");
		String idString = request.getParameter("idString");
		String databaseId = request.getParameter("databaseId");
		String tableName = request.getParameter("tableName");
		String targetDataSourceId = request.getParameter("targetDataSourceId");
		String targetTableName = request.getParameter("targetTableName");
		Integer clichId = Integer.parseInt(request.getParameter("clichId"));
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		Classes classes = publicService.findClasses(Integer.parseInt(classesId));
		List<Classes> classesAll= publicService.getClasses();
		List<DataProperty> dataProperties = publicService.getDataProperty(classes);
		Integer departmentid =(Integer) request.getSession().getAttribute("userid");
		HashMap<String, Object> data = new HashMap<String, Object>();
		for (DataProperty dp : dataProperties) {
			String dataKey = "";
			String dataValue = "";
			if (dp.getAdminDetailShow().equals("1")) {
					dataKey = dp.getNameEn();
					dataValue = request.getParameter(dataKey);
					if(dp.getDataTypeId() == 14){
						dataValue = MD5.convert(dataValue);
					}
					if(dp.getDataTypeId() == 5 || dp.getDataTypeId() == 6 || dp.getDataTypeId() == 8 || dp.getDataTypeId() == 16|| dp.getDataTypeId() == 17|| dp.getDataTypeId() == 24|| dp.getDataTypeId() == 25|| dp.getDataTypeId() == 26|| dp.getDataTypeId() == 27){
						if(dataValue != null && !"".equals(dataValue)){
							dataValue = dataValue.replaceAll(uploadPath, "");
						}
					}
					data.put(dataKey, dataValue);
			}
		}
			String createUserId = departmentid.toString();
			String status = "0";
			String version = "1.0";
			String createTime = DateUtils.getDateTime();
			String dataSource = "1";
		    String id =null;
		   
		    String logZn=null;
		    for(Classes c:classesAll){
		    	if(c.getNameEn().equals(subjectClassesEn)){
		    		logZn=c.getNameZh();
		    	}
		    }
		    
		    User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		    int logTime=0;
		    try {
		    	if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
		    		if(null != targetDataSourceId && !"".equals(targetDataSourceId)&& !"undefined".equals(targetDataSourceId)){
		    			id =dynamicService.addDynamicData(classesEn, data, createTime, createUserId, status, version, classesId, dataSource,targetDataSourceId,targetTableName);
				    	//dynamicService.submitDynamicData(classesEn, createTime,createUserId, id);
				    	dynamicService.saveDynamicObjectDataST(subjectClassesEn, idString, classesEn, id, clichId, createTime,departmentid.toString(),databaseId,tableName,targetDataSourceId,targetTableName);
				    	/** 修改主表时间  开始*/
				    	Map<String,Object> dynamic =dynamicService.findDynamicData(subjectClassesEn, idString,databaseId,tableName);
						String upid = dynamic.get("id").toString();
						String upstatus = dynamic.get("status").toString();
						String upversion = dynamic.get("version").toString();
						dynamic.remove("update_time");
						dynamic.remove("update_user_id");
						String updateUserId = departmentid.toString();
						String updateTime = DateUtils.getDateTime();
						dynamicService.editDynamicData(subjectClassesEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid,databaseId,tableName);
						/** 修改主表时间 结束    */
		    		}else{
		    			id =dynamicService.addDynamicData(classesEn, data, createTime, createUserId, status, version, classesId, dataSource);
				    	//dynamicService.submitDynamicData(classesEn, createTime,createUserId, id);
				    	dynamicService.saveDynamicObjectDataS(subjectClassesEn, idString, classesEn, id, clichId, createTime,departmentid.toString(),databaseId,tableName);
				    	/** 修改主表时间  开始*/
				    	Map<String,Object> dynamic =dynamicService.findDynamicData(subjectClassesEn, idString,databaseId,tableName);
						String upid = dynamic.get("id").toString();
						String upstatus = dynamic.get("status").toString();
						String upversion = dynamic.get("version").toString();
						dynamic.remove("update_time");
						dynamic.remove("update_user_id");
						String updateUserId = departmentid.toString();
						String updateTime = DateUtils.getDateTime();
						dynamicService.editDynamicData(subjectClassesEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid,databaseId,tableName);
						/** 修改主表时间 结束    */
		    		}
		    	}else{
		    		if(null != targetDataSourceId && !"".equals(targetDataSourceId)&& !"undefined".equals(targetDataSourceId)){
		    			id =dynamicService.addDynamicData(classesEn, data, createTime, createUserId, status, version, classesId, dataSource,targetDataSourceId,targetTableName);
				    	//dynamicService.submitDynamicData(classesEn, createTime,createUserId, id);
				    	dynamicService.saveDynamicObjectDataT(subjectClassesEn, idString, classesEn, id, clichId, createTime,departmentid.toString(),targetDataSourceId,targetTableName);
				    	/** 修改主表时间  开始*/
				    	Map<String,Object> dynamic =dynamicService.findDynamicData(subjectClassesEn, idString);
						String upid = dynamic.get("id").toString();
						String upstatus = dynamic.get("status").toString();
						String upversion = dynamic.get("version").toString();
						dynamic.remove("update_time");
						dynamic.remove("update_user_id");
						String updateUserId = departmentid.toString();
						String updateTime = DateUtils.getDateTime();
						dynamicService.editDynamicData(subjectClassesEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid);
						/** 修改主表时间 结束    */
		    		}else{
		    			id =dynamicService.addDynamicData(classesEn, data, createTime, createUserId, status, version, classesId, dataSource);
				    	//dynamicService.submitDynamicData(classesEn, createTime,createUserId, id);
				    	dynamicService.saveDynamicObjectData(subjectClassesEn, idString, classesEn, id, clichId, createTime,departmentid.toString());
				    	/** 修改主表时间  开始*/
				    	Map<String,Object> dynamic =dynamicService.findDynamicData(subjectClassesEn, idString);
						String upid = dynamic.get("id").toString();
						String upstatus = dynamic.get("status").toString();
						String upversion = dynamic.get("version").toString();
						dynamic.remove("update_time");
						dynamic.remove("update_user_id");
						String updateUserId = departmentid.toString();
						String updateTime = DateUtils.getDateTime();
						dynamicService.editDynamicData(subjectClassesEn, dynamic, updateTime, updateUserId, upstatus, upversion, upid);
						/** 修改主表时间 结束    */
		    		}
		    	}
				
		    } catch (Exception e) {
		    	this.log(user.getId(), "knowledge_data", classesId, null, "【"+user.getNickname()+"】【新增】知识【"+logZn+"】库关联知识【"+classes.getNameZh()+"】库的数据失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "knowledge_data", classesId, idString, "【"+user.getNickname()+"】【新增】知识【"+logZn+"】库关联知识【"+classes.getNameZh()+"】库ID为【"+id+"】的数据成功！", 0);
			}
	}
	
	
	/**
	 * 知识加工-关联关系-详情
	 * zhongfeng
	 * 2016.10.26
	 */
	@RequestMapping("querychoicerrelevance")
	public ModelAndView toKnowledgeDeleteDataQueryChoicerRelevance(HttpServletRequest request,HttpServletResponse response) throws Exception {
		// 三级。如矿石等
		String id = request.getParameter("id");
		int classesId = Integer.parseInt(request.getParameter("classesId"));
		String dataSourceId = request.getParameter("dataSourceId");
		String targetTableName = request.getParameter("targetTableName");
		//ObjectProperty objectProperty=publicService.findObjectProperty(classesId);
		
		Classes classes = publicService.findClasses(classesId);

	
		// 标题
		String headline= classes.getNameZh();
		// 描述
		String describe = classes.getDescription();
		List<DataProperty> dataProperties = publicService.getDataProperty(classes);
		List<DataType> dataType = publicService.getDataType();
		/*for(DataProperty dp : dataProperties){
			Integer dataTypeId= dp.getDataTypeId();
			dp.setDataType(publicService.findDataType(dataTypeId));
		}*/
		Map<String, Object> data =null;
		if(null != dataSourceId && !"".equals(dataSourceId)&& !"undefined".equals(dataSourceId)&& !"null".equals(dataSourceId)){
			data = dynamicService.findDynamicData(classes.getNameEn(),id,dataSourceId,targetTableName);
		}else{
			data = dynamicService.findDynamicData(classes.getNameEn(),id);
		}
		HashMap<String, Object> picturePath =  new LinkedHashMap<String, Object>();
		 //获取服务器地址
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		 String adjunctPath =  request.getContextPath() + "/adjunct/";
		//字典
		 List<Map<String, Object>> arrList = new ArrayList<Map<String,Object>>();
		 List<Map<Object, Object>> dicNameEn = new ArrayList<Map<Object,Object>>();
		 Map<String, Object> multiList = new LinkedHashMap<String, Object>();
		//List<DictItem> DictItem =new ArrayList<DictItem>();
		 Map<Integer, Integer> dictsMap = new HashMap<Integer, Integer>();
			for(DataProperty dp : dataProperties){
				dp.setNameEn(dp.getNameEn());
				if(null == dp.getFormValidationRegulation()){
					dp.setFormValidationRegulation("");
				}
				Integer dataTypeId= dp.getDataTypeId();
				Integer dictId=dp.getDictId();
				if(dictId != 0){
					Dict dicts = publicService.findDict(dictId);
					dictsMap.put(dp.getDictId(), dicts.getDictType());
					if(dicts.getDictType()==2){
						Map<Object, Object> dicNameEnMap = new HashMap<Object, Object>();
						dicNameEnMap.put("dictDpId", dp.getNameEn());
						dicNameEn.add(dicNameEnMap);
					}
					Dict dict = new Dict();
					dict.setId(dictId);
					List<DictItem> dictItem = publicService.getDictItem(dict);
					for(DictItem dic : dictItem){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("dpid", dp.getId());
						map.put("dicid", dic.getId());
						map.put("nameZh", dic.getNameZh());
						map.put("value", dic.getValue());
						arrList.add(map);
					}
						String multis = data.get(dp.getNameEn()).toString();
						String multiname="";
						if(multis!=null && !"".equals(multis)){
							String [] multimap = multis.split(",");
							for (int i = 0; i < multimap.length; i++) {
								HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
								queryParams.put("=,dict_id", dp.getDictId());
								queryParams.put("=,value", multimap[i]);
								List<DictItem> aDictItems =publicService.getDictItem(queryParams, 1, publicService.getDictItemCount(queryParams));
								if(aDictItems.size()>0 ){
									DictItem aDictItem=aDictItems.get(0);
									multiname += aDictItem.getNameZh()+",";
								}
							}
							if(!"".equals(multiname) && multiname != null){
								multiname = multiname.substring(0, multiname.length()-1);
								multiList.put(dp.getNameEn(), multiname);
							}
						}
				}
				//dp.setDataType(publicService.findDataType(dataTypeId));
				
				if(dp.getDataTypeId()==16 || dp.getDataTypeId() == 24|| dp.getDataTypeId() == 25){
					String wenjian = (String) data.get(dp.getNameEn());
					if(wenjian != null){
						String [] wenjiansz =wenjian.split("%");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						data.put(dp.getNameEn(), danwenjian);
						picturePath.put(dp.getNameEn(), wenjian);
					}
				}
				if(dp.getDataTypeId() == 26){
					String tupian = (String) data.get(dp.getNameEn());
					if(tupian != null && !"".equals(tupian)){
						String [] tupiansz =tupian.split(";");
						String dantupian = "";
						for (int j = 0; j < tupiansz.length; j++) {
							if(tupiansz[j] != null && !"".equals(tupiansz[j])){
								dantupian +="<a href=javascript:querypicture('"+uploadPath+tupiansz[j]+"') ><img src="+uploadPath+tupiansz[j]+" width='30' height='30'/></a>&nbsp;&nbsp;";
							}
						}
						data.put(dp.getNameEn(), dantupian);
						picturePath.put(dp.getNameEn(), tupian);
					}
				}
				if(dp.getDataTypeId() == 5 || dp.getDataTypeId() == 6 ){
					String path = (String) data.get(dp.getNameEn());
					if(path != null && !"".equals(path)){
						String url = CommonUrl.addPrefixPath("src", path, uploadPath);
						data.put(dp.getNameEn(),url);
					}
				}
				if(dp.getDataTypeId() != null && dp.getDataTypeId()==17 ){
					String wenjian = (String) data.get(dp.getNameEn());
					if(wenjian != null){
						String [] wenjiansz =wenjian.split("%");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						data.put(dp.getNameEn(), danwenjian);
						picturePath.put(dp.getNameEn(), wenjian);
					}
				}
				if(dp.getDataTypeId() != null && dp.getDataTypeId()==27 ){
					String wenjian = (String) data.get(dp.getNameEn());
					if(wenjian != null){
						String [] wenjiansz =wenjian.split("∷");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						data.put(dp.getNameEn(), danwenjian);
						picturePath.put(dp.getNameEn(), wenjian);
					}
				}
			}
		for (int i = 0; i < dicNameEn.size(); i++) {
			Map<Object, Object> dic =dicNameEn.get(i);
			dic.put("jieguoji", data.get(dic.get("dictDpId")));
			
		}
		
		ModelAndView view = new ModelAndView();
		view.addObject("classesEn", classes.getNameEn());
		view.addObject("classesId", classesId);
		view.addObject("idString", id);
		view.addObject("headline", headline);
		view.addObject("describe", describe);
		view.addObject("dataProperties", dataProperties);
		view.addObject("dictsMap", dictsMap);
		view.addObject("dataType", dataType);
		view.addObject("data", data);
		view.addObject("dicNameEn", dicNameEn);
		view.addObject("dicValue", dicNameEn);
		view.addObject("picturePath", picturePath);
		view.addObject("resultString", arrList);
		view.addObject("multiList", multiList);
		view.addObject("uploadPath", uploadPath);
		view.addObject("adjunctPath", adjunctPath);
		view.setViewName("/modules/repository/knowledge_edit_data_queryrelevance");
		return view;
	}
	
	
	/**
	 * 知识加工-添加消息-ajax
	 * zhongfeng
	 * 2016.9.12
	 */
	@RequestMapping("knowledge-edit-data-detail-ajax.html")
	public void toKnowledgeEditDataClassDetailAjax(HttpServletRequest request,HttpServletResponse response) throws Exception {
	
		String nameEn = request.getParameter("nameEn");
		String did = request.getParameter("did");
		// 值
		List<DataProperty> dataProperties = searchService.getDataPropertyListCache(nameEn);			
		
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		
		for(DataProperty dp :dataProperties){
			if(dp.getId().equals(did) && dp.getDictId() != 0){
				Dict dict = new Dict();
				Integer dictId=dp.getDictId();
				dict.setId(dictId);
				List<DictItem> dictItem  = publicService.getDictItem(dict);
					for(DictItem dic : dictItem){
							mp = new LinkedHashMap<String, Object>();
							mp.put("id", dic.getId());
							mp.put("name", dic.getNameZh());
							if (dic.getDictId() == dictId) {
								mp.put("pId", dic.getDictItemId());
							} else {
								mp.put("pId", "0");
							}
							r.add(mp);
					}
				}
			}
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	//上传图片
	@RequestMapping("knowledge-edit-data-detail-upload.html")
	public void toKnowledgeEditDataClassDetailUpload(HttpServletRequest request,HttpServletResponse response) throws IOException {
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;  
		  MultipartFile file =multipartRequest.getFile("uploadify");
		  
		  //获取服务器地址
		  String path =  XxlConfClient.get("dal.file.path", "") +"/";
		  ServletContext sc = request.getSession().getServletContext();
		  //附件存放服务器路径
		  String dir = "";
		   String fileName = file.getOriginalFilename();
	//	   String realName = fileName.substring(0, fileName.indexOf("."));
		   //防止文件被覆盖，以纳秒生成文件名称
		   Long _l = System.nanoTime();
		   String _extName = fileName.substring(fileName.indexOf("."));
		   Date d = new Date();  
	       String s = null;
		   DateFormat sdf3 = new SimpleDateFormat("yyyyMMdd");  
	       s = sdf3.format(d);  
		   String lujin="upload/"+s;
		   dir = path+lujin;;
		 //如果文件夹不存在，则创建文件夹
			  if (!new File(dir).exists()){
				  new File(dir).mkdirs();
			  }
		   
		   fileName = _l + _extName;
		   
		   String uploadPath =  XxlConfClient.get("dal.file.path", "") +"/"+lujin;
		   String queryPath =   XxlConfClient.get("dal.file.server", "") +"/" + lujin+"/" +fileName;
		   //存储格式为：/项目名/upload/yingjiwuzhi/43038800303864.log	
		   //存储到数据库的相对路径
		   
		   String responseStr=""; 
		   try {
			   FileUtils.writeByteArrayToFile(new File(uploadPath, fileName),file.getBytes());//服务器中生成文件
			   responseStr=lujin+"/" +fileName;  
		   }catch (IOException e) {
			  e.printStackTrace();
			  responseStr="上传失败";  
		   }
		   response.getWriter().print(responseStr);
	}
	//上传附件
	@RequestMapping("knowledge-edit-data-detail-file.html")
	public void toKnowledgeEditDataClassDetailFile(HttpServletRequest request,HttpServletResponse response) throws IOException {
		//上传附件
		String id =request.getParameter("id");
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;  
		  MultipartFile file =multipartRequest.getFile(id);
		  
		  //获取服务器地址
		  String filePath = XxlConfClient.get("dal.file.path", "")+"/";
		  //附件存放服务器路径
		  String dir = "";
		  
		   String fileName = file.getOriginalFilename();
	//	   String realName = fileName.substring(0, fileName.indexOf("."));
		   //防止文件被覆盖，以纳秒生成文件名称
		   Long _l = System.nanoTime();
		   String _extName = fileName.substring(fileName.indexOf("."));
		  
		   Date d = new Date();  
	       String s = null;
		   DateFormat sdf3 = new SimpleDateFormat("yyyyMMdd");  
	       s = sdf3.format(d);  
		   String lujin="file/"+s;
		   dir = filePath+lujin;;
		 //如果文件夹不存在，则创建文件夹
			  if (!new File(dir).exists()){
				  new File(dir).mkdirs();
			  }
		   
		   fileName = _l + _extName;
		   
		   //存储格式为：/项目名/upload/yingjiwuzhi/43038800303864.log	
		   //存储到数据库的相对路径
		   String responseStr=""; 
		   try {
			   FileUtils.writeByteArrayToFile(new File(filePath+lujin, fileName),file.getBytes());//服务器中生成文件
			   responseStr=lujin+"/" +fileName;  
		   }catch (IOException e) {
			  e.printStackTrace();
			  responseStr="上传失败";  
		   }
		   response.getWriter().print(responseStr);
	}
	/**
	 * 添加 方法
	 * zhongfeng
	 * 2016.9.12
	 */
	
	@RequestMapping("knowledge-edit-data-detail-add.html")
	public ModelAndView toKnowledgeEditDataClassDetailAdd(HttpServletRequest request) throws Exception{
		
		// 三级。如矿石等
		String classesEn = request.getParameter("classesEn");
		String classesId = request.getParameter("classesId");
		String chartName = request.getParameter("chartName");
		String databaseName = request.getParameter("databaseName");
		
		Classes classes = publicService.findClasses(Integer.parseInt(classesId));
		List<DataProperty> dataProperties = publicService.getDataProperty(classes);
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		
		Integer userid =(Integer) request.getSession().getAttribute("userid");
		User user = publicService.findUser(userid);
		/*
		 * 判断审核
		 */
		HashMap<String, Object> queryRoleCountParams = new HashMap<String, Object>();
		queryRoleCountParams.put("=,user_id", userid);
		queryRoleCountParams.put("=,role_id", 25);
		int audit= 0;
		List<UserRole> userRoleList= publicService.getUserRole(queryRoleCountParams);
		if(null != userRoleList && userRoleList.size()>0){
			audit = userRoleList.get(0).getId();
		}
		HashMap<String, Object> data = new HashMap<String, Object>();
		Map<String,Object> conditions = null;
		int xingMing=0;
		int shouJi=0;
		String addDynamicDataid=null;
		if(dataProperties.size()>0){
		for (DataProperty dp : dataProperties) {
			String dataKey = "";
			String dataValue = "";
			if (dp.getAdminDetailShow().equals("1")) {
					dataKey = dp.getNameEn();
					dataValue = request.getParameter(dataKey);
					if(classesEn.equals("ke_hu_zi_liao")){
						if(dataKey.equals("xing_ming")){
							conditions = new LinkedHashMap<String, Object>();
							conditions.put("=xing_ming", dataValue);
							long count = 0;
							if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
								count = dynamicService.getDynamicCount(classesEn, conditions,databaseName,chartName);
							}else{
								count = dynamicService.getDynamicCount(classesEn, conditions);
							}
							if(count != 0){
								xingMing=1;
								break;
							}
						}
						if(dataKey.equals("shou_ji")){
							if(dataValue != null && !"".equals(dataValue)){
								conditions = new LinkedHashMap<String, Object>();
								conditions.put("=shou_ji", dataValue);
								long count = 0;
								if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
									count = dynamicService.getDynamicCount(classesEn, conditions,databaseName,chartName);
								}else{
									count = dynamicService.getDynamicCount(classesEn, conditions);
								}
								if(count != 0){
									shouJi=1;
									break;
								}
							}
						}
					}
					if(dp.getDataTypeId() == 14){
						dataValue = MD5.convert(dataValue);
					}
					if(dp.getDataTypeId() == 5 || dp.getDataTypeId() == 6  || dp.getDataTypeId() == 8 || dp.getDataTypeId() == 16|| dp.getDataTypeId() == 17 || dp.getDataTypeId() == 24|| dp.getDataTypeId() == 25|| dp.getDataTypeId() == 26|| dp.getDataTypeId() == 27){
						if(dataValue != null && !"".equals(dataValue)){
							dataValue = dataValue.replaceAll(uploadPath, "");
						}
					}
					data.put(dataKey, dataValue);
			}
			
		}
			String createUserId = userid.toString();
			String status = "0";
			String version = "1.0";
			String createTime = DateUtils.getDateTime();
			String dataSource = "1";
			//是否启用工作流
			Workflow workflow = null;
			WorkflowNode workflowNode = null;
			HashMap<String, Object> queryWorkflowParams = new HashMap<String, Object>();
			queryWorkflowParams.put("=,classes_en", classesEn);
			List<Workflow> workflowList = publicService.getWorkflow(queryWorkflowParams, 1, 1);
			if(null != workflowList && workflowList.size()>0){
				workflow = workflowList.get(0);
				if(workflow.getStatus() == 1){
					status = "-1";
					HashMap<String, Object> queryWorkflowNodeParams = new HashMap<String, Object>();
					queryWorkflowNodeParams.put("=,workflow_id", workflow.getId());
					queryWorkflowNodeParams.put("=,sort", 1);
					List<WorkflowNode> workflowNodeList = publicService.getWorkflowNode(queryWorkflowNodeParams, 1, 1);
					if(null != workflowNodeList && workflowNodeList.size()>0){
						workflowNode = workflowNodeList.get(0);
						HashMap<String, Object> queryUserParams = new HashMap<String, Object>();
						queryUserParams.put("=,username", workflowNode.getExecutor());
						List<User> userList= publicService.getUser(queryUserParams, 1, 1);
						if(null != userList && userList.size()>0){
							data.put("submit_user_id", userList.get(0).getId());
						}
					}
				}
			}
			
			int logTime=0;
			if (xingMing != 1 && shouJi != 1) {
			    try {
			    	if( null != databaseName && !"".equals(databaseName) && !"undefined".equals(databaseName)){
			    		addDynamicDataid = dynamicService.addDynamicData(classesEn, data, createTime, createUserId, status, version, classesId, dataSource,databaseName,chartName);
			    	}else{
			    		addDynamicDataid = dynamicService.addDynamicData(classesEn, data, createTime, createUserId, status, version, classesId, dataSource);
			    	}
			    	 //获取服务器地址
					String saveVersion = XxlConfClient.get("dal.store.is.version", "");
			    	if("true".equals(saveVersion)){
			    		dynamicService.addDynamicDataVersion(classesEn, data, createTime,createUserId, status, version, classesId, dataSource, addDynamicDataid);
			    	}
					//dynamicService.submitDynamicData(classesEn, createTime,createUserId, addDynamicDataid);
			    } catch (Exception e) {
					this.log(user.getId(), "knowledge_data", classesId, null, "【"+user.getNickname()+"】【新增】知识【"+classes.getNameZh()+"】库的数据失败！请检查参数是否正确！", 1);
					logTime=1;
					e.printStackTrace();
				}
			    if(logTime ==0){
			    	this.log(user.getId(), "knowledge_data", classesId, addDynamicDataid, "【"+user.getNickname()+"】【新增】知识【"+classes.getNameZh()+"】库ID为：【"+addDynamicDataid+"】的数据成功！", 0);
			    }
			}
		}
		//获取服务器地址
		String serversPath =  XxlConfClient.get("dal.file.server", "") +"/";
		ModelAndView view = new ModelAndView();
		view.addObject("classesEn", classesEn);
		view.addObject("classesId", classesId);
		view.addObject("serversPath", serversPath);
		view.addObject("chartName", chartName);
		view.addObject("databaseName", databaseName);
		view.addObject("audit", audit);
		if (xingMing != 1 && shouJi != 1) {
			view.addObject("id", addDynamicDataid);
			view.setViewName("redirect:/show-edit-data-detail-update.html");
		}else{
			view.setViewName("redirect:/show-edit-data-detail.html");
		}
			return view;

	}

	/**
	 * 页面单个修改
	 * zhongfeng
	 * 2016.9.29
	 */
	@RequestMapping("knowledge-edit-data-partUpdate-ajax.html")
	public void toKnowledgeEditDataPartUpdateAjax(HttpServletRequest request,HttpServletResponse response) throws Exception {
		response.setCharacterEncoding("utf-8");
		String text =request.getParameter("text");
		String classesEn =request.getParameter("classesEn");
		String id =request.getParameter("id");
		String key =request.getParameter("key");
		Map<String, Object> dynamicData=dynamicService.findDynamicData(classesEn, id);
		dynamicData.put(key, text);
		dynamicData.remove("update_time");
		dynamicData.remove("update_user_id");
		dynamicData.remove("status");
		dynamicData.remove("version");
		dynamicData.remove("id");
		dynamicData.remove("dataSource");
		
		/*Cookie[] cookies = request.getCookies();
		String userid="";
		for (int i = 1; i < cookies.length; i++) {
			if("userId".equals(cookies[i].getName())){
				userid= cookies[i].getValue();
			}
		}
		int lg = Integer.parseInt(userid);*/
		Integer departmentid =(Integer) request.getSession().getAttribute("userid");
		//User aUser = publicService.findUser(userid);
		String updateUserId = departmentid.toString();
		String status = "0";
		String version = "1.0";
		String updateTime = DateUtils.getDateTime();
		HashMap<String, Object> editText = new LinkedHashMap<String, Object>();
		editText.put(key, dynamicData.get(key));
		
		dynamicService.editDynamicData(classesEn, editText, updateTime, updateUserId, status, version, id);
		//dynamicService.submitDynamicData(classesEn, updateTime,updateUserId, id);
	    Map<String, Object> data=dynamicService.findDynamicData(classesEn, id);
	    Object updataText=data.get(key);
	    JSONObject json = new JSONObject();
	    json.put("result", updataText);
	    response.getWriter().print(json);
	}
			
	/**
	 * 修改 页面
	 * zhongfeng
	 * 2016.9.12
	 * @throws UnsupportedEncodingException 
	 */
	
	@RequestMapping("show-edit-data-detail-update.html")
	public ModelAndView toKnowledgeEditDataClassDetailUpdte(HttpServletRequest request) throws UnsupportedEncodingException {
		
		// 三级。如矿石等
		String classesEn = request.getParameter("classesEn");
		String classesId = request.getParameter("classesId");
		String dynamicDataId = request.getParameter("id");
		String createUserId = request.getParameter("createUserId");
		String curr = request.getParameter("curr");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		String searchType = request.getParameter("searchType");
		String status = request.getParameter("status");
		String chartName = request.getParameter("chartName");
		String databaseName = request.getParameter("databaseName");
		/*JSONObject jb = JSONObject.fromObject(screenContent);
		Map screenContentmap = (Map)jb;
		HashMap<String, Object> conditions = new HashMap<String, Object>();
		for (Object key : screenContentmap.keySet()) {
			conditions.put(key.toString(), screenContentmap.get(key));
		}*/
		String userid = request.getSession().getAttribute("userid").toString();
		User user = publicService.findUser(Integer.parseInt(userid));
		/*
		 * 判断审核
		 */
		HashMap<String, Object> queryRoleCountParams = new HashMap<String, Object>();
		queryRoleCountParams.put("=,user_id", userid);
		queryRoleCountParams.put("=,role_id", 25);
		int audit= 0;
		List<UserRole> userRoleList= publicService.getUserRole(queryRoleCountParams);
		if(null != userRoleList && userRoleList.size()>0){
			audit = userRoleList.get(0).getId();
		}
		
		HashMap<String, Object> queryParamsUser = new HashMap<String, Object>();
		queryParamsUser.put("=,userId",  user.getId());
		List<UserRole> userRole = publicService.getUserRole(queryParamsUser);
		String roleName="";
		if(userRole != null && userRole.size()>0){
			roleName = publicService.findRole(userRole.get(0).getRoleId()).getName();
		}
		Classes classes = publicService.findClasses(Integer.parseInt(classesId));
		// 标题
		String headline= classes.getNameZh();
		// 描述
		String describe = classes.getDescription();
		List<DataProperty> dataProperties = publicService.getDataProperty(classes);
		List<DataType> dataType = publicService.getDataType();
		String select="";
		for(DataProperty dp : dataProperties){ 
			if("1".equals(dp.getAdminListShow()) && request.getParameter(dp.getNameEn()) !=null && !"".equals(request.getParameter(dp.getNameEn()))){
				String selectValue =request.getParameter(dp.getNameEn());
				if(selectValue !=null && !"".equals(selectValue)){
					select += "&"+dp.getNameEn()+"="+selectValue;
				}
			}else{
				if(dp.getDataTypeId() == 10 || dp.getDataTypeId() == 11 || dp.getDataTypeId() == 12 || dp.getDataTypeId() == 13 ){
					String selectValue_startTime =request.getParameter(dp.getNameEn()+"_startTime");
					if(selectValue_startTime !=null && !"".equals(selectValue_startTime)){
						select += "&"+dp.getNameEn()+"_startTime="+selectValue_startTime;
					}
					String selectValue_endTime =request.getParameter(dp.getNameEn()+"_endTime");
					if(selectValue_endTime !=null && !"".equals(selectValue_endTime)){
						select += "&"+dp.getNameEn()+"_endTime="+selectValue_endTime;
					}
				}
			}
		}
		if(createUserId !=null && !"".equals(createUserId)){
			select += "&createUserId="+createUserId;
		}
		if(curr !=null && !"".equals(curr)){
			select += "&curr="+curr;
		}
		if(startTime !=null && !"".equals(startTime)){
			select += "&startTime="+startTime;
		}
		if(endTime !=null && !"".equals(endTime)){
			select += "&endTime="+endTime;
		}
		if(searchType !=null && !"".equals(searchType)){
			select += "&searchType="+searchType;
		}
		if(status !=null && !"".equals(status)){
			select += "&status="+status;
		}
		Map<String, Object> data = null;
		if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
			data = dynamicService.findDynamicData(classesEn,dynamicDataId,databaseName,chartName);
		}else{
			data = dynamicService.findDynamicData(classesEn,dynamicDataId);
		}
		
		HashMap<String, Object> picturePath =  new LinkedHashMap<String, Object>();
		
		//获取服务器地址
		 String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		 String adjunctPath =  request.getContextPath() + "/adjunct/";
		//字典
		 
		 List<Map<String, Object>> arrList = new ArrayList<Map<String,Object>>();
		 List<Map<Object, Object>> dicNameEn = new ArrayList<Map<Object,Object>>();
		 Map<String, Object> multiList = new LinkedHashMap<String, Object>();
		//List<DictItem> DictItem =new ArrayList<DictItem>();
		 Map<Integer, Integer> dictsMap = new HashMap<Integer, Integer>();
			for(DataProperty dp : dataProperties){
				dp.setNameEn(dp.getNameEn());
				
				if(null == dp.getFormValidationRegulation()){
					dp.setFormValidationRegulation("");
				}
				Integer dataTypeId= dp.getDataTypeId();
				Integer dictId=dp.getDictId();
				if(dictId != 0){
					Dict dicts = publicService.findDict(dictId);
					dictsMap.put(dp.getDictId(), dicts.getDictType());
					if(dicts.getDictType()==2){
						Map<Object, Object> dicNameEnMap = new HashMap<Object, Object>();
						dicNameEnMap.put("dictDpId", dp.getNameEn());
						dicNameEn.add(dicNameEnMap);
					}
					Dict dict = new Dict();
					dict.setId(dictId);
					List<DictItem> dictItem = publicService.getDictItem(dict);
					for(DictItem dic : dictItem){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("dpid", dp.getId());
						map.put("dicid", dic.getId());
						map.put("nameZh", dic.getNameZh());
						map.put("value", dic.getValue());
						arrList.add(map);
					}
					Object multis = data.get(dp.getNameEn());
					String multiname="";
					if(multis!=null && !"".equals(multis)){
						String [] multimap = multis.toString().split(",");
						for (int i = 0; i < multimap.length; i++) {
							HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
							queryParams.put("=,dict_id", dp.getDictId());
							queryParams.put("=,value", multimap[i]);
							List<DictItem> aDictItems =publicService.getDictItem(queryParams, 1, publicService.getDictItemCount(queryParams));
							if(aDictItems.size()>0){
								DictItem aDictItem = aDictItems.get(0);
								multiname += aDictItem.getNameZh()+",";
							}
						}
						if(!"".equals(multiname) && multiname != null){
							multiname = multiname.substring(0, multiname.length()-1);
							multiList.put(dp.getNameEn(), multiname);
						}
					}
				}
				//dp.setDataType(publicService.findDataType(dataTypeId));
				
				if(dp.getDataTypeId()==16 || dp.getDataTypeId() == 24|| dp.getDataTypeId() == 25){
					String wenjian = (String) data.get(dp.getNameEn());
					if(wenjian != null && !"".equals(wenjian)){
						String [] wenjiansz =wenjian.split("%");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian ="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						data.put(dp.getNameEn(), danwenjian);
						picturePath.put(dp.getNameEn(), wenjian);
					}else{
						picturePath.put(dp.getNameEn(), wenjian);
					}				}
				if(dp.getDataTypeId() != null && dp.getDataTypeId()==17 ){
					String wenjian = (String) data.get(dp.getNameEn());
					if(wenjian != null && !"".equals(wenjian)){
						String [] wenjiansz =wenjian.split("%");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						data.put(dp.getNameEn(), danwenjian);
						picturePath.put(dp.getNameEn(), wenjian);
					}else{
						picturePath.put(dp.getNameEn(), wenjian);
					}
				}
				if(dp.getDataTypeId() != null && dp.getDataTypeId()==27 ){
					String wenjian = (String) data.get(dp.getNameEn());
					if(wenjian != null && !"".equals(wenjian)){
						String [] wenjiansz =wenjian.split("∷");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						data.put(dp.getNameEn(), danwenjian);
						picturePath.put(dp.getNameEn(), wenjian);
					}else{
						picturePath.put(dp.getNameEn(), wenjian);
					}
				}
				if(dp.getDataTypeId() != null && dp.getDataTypeId()==26 ){
					String tupian = (String) data.get(dp.getNameEn());
					if(tupian != null && !"".equals(tupian)){
						String [] tupiansz =tupian.split(";");
						String dantupian = "";
						for (int j = 0; j < tupiansz.length; j++) {
							if(tupiansz[j] != null && !"".equals(tupiansz[j])){
								dantupian +="<a href=javascript:querypicture('"+uploadPath+tupiansz[j]+"') ><img src="+uploadPath+tupiansz[j]+" width='30' height='30'/></a>&nbsp;&nbsp;";
							}
						}
						data.put(dp.getNameEn(), dantupian);
						picturePath.put(dp.getNameEn(), tupian);
					}else{
						picturePath.put(dp.getNameEn(), tupian);
					}
				}
				if(dp.getDataTypeId() == 5 || dp.getDataTypeId() == 6 ){
					String path = (String) data.get(dp.getNameEn());
					if(path != null && !"".equals(path)){
						String url = CommonUrl.addPrefixPath("src", path, uploadPath);
						data.put(dp.getNameEn(), url);
					}
				}
			}
		//导航
		List<Classes> objectPropertyClasses = publicService.getClasses();
		List<ObjectProperty> objectProperty = publicService.getObjectProperty(classes);
			for(ObjectProperty op :objectProperty){
				//op.setRelevanceClasses(publicService.findClasses(op.getRelevanceClassesId()));
			}
		/*String dicValue=null;
		if(dicNameEn !=null){
			
			dicValue=(String) data.get(dicNameEn);
		
		}*/
		for (int i = 0; i < dicNameEn.size(); i++) {
			Map<Object, Object> dic =dicNameEn.get(i);
			dic.put("jieguoji", data.get(dic.get("dictDpId")));
			
		}
		
		for(DataProperty dp : dataProperties){
			if(data.get(dp.getNameEn()) == null){
				data.put(dp.getNameEn(), "");
			}
		}
		
		
		/**
		 * 审核流程 start
		 */
		String auditFlow = "";
		HashMap<String, Object> queryWorkflowExecuteParams = new HashMap<String, Object>();
		queryWorkflowExecuteParams.put("=,classes_en", classesEn);
		queryWorkflowExecuteParams.put("=,resource_id", dynamicDataId);
		List<WorkflowExecute> workflowExecuteList = publicService.getWorkflowExecute(queryWorkflowExecuteParams, 1, publicService.getWorkflowExecuteCount(queryWorkflowExecuteParams));
		if(null != workflowExecuteList && workflowExecuteList.size()>0){
			for (int i = 0; i < workflowExecuteList.size(); i++) {
				String direction = "";
				if((i+1)%2==0){
					direction = "left-aligned";
				}
				WorkflowExecute workflowExecute = workflowExecuteList.get(i);
				String color = "";//颜色
				String icon = "";//图标
				if("1".equals(workflowExecute.getStatus().toString())){
					color = "green";
					icon = "fa-check";
				}else{
					color = "red";
					icon = "fa-times";
				}
				String userName = "";//审核人
				HashMap<String, Object> queryUserParams = new HashMap<String, Object>();
				queryUserParams.put("=,username", workflowExecute.getCreateUser());
				List<User> userList= publicService.getUser(queryUserParams, 1, 1);
				if(null != userList && userList.size()>0){
					userName = userList.get(0).getNickname();
				}
				String createTime = workflowExecute.getCreateTime();//审核时间
				auditFlow +="<article class=\"timeline-entry "+direction+"\">"
							+"<div class=\"timeline-entry-inner\">"
							+"<time datetime=\""+createTime+"\" class=\"timeline-time\"><span style=\"font-size: 14px;\">"+createTime.substring(0, 10)+"</span><span>"+createTime.substring(11, createTime.length())+"</span></time>"
							+"<div class=\"timeline-icon bg-"+color+"\" style=\"border-color:#33485c;\"><i class=\"fa "+icon+"\"></i></div>"
							+"<div class=\"timeline-label bg-"+color+"\">"
							+"<h4 class=\"timeline-title\">"+userName+"</h4>"
							+"<p>"+workflowExecute.getReason()+"</p>"
							+"</div>"
							+"</div>";
							if("1".equals(data.get("status")) && (i+1) == workflowExecuteList.size()){
								auditFlow += "<div class=\"timeline-entry-inner\">"
										  +"<div style=\"-webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg);border-color:#33485c;\" class=\"timeline-icon bg-"+color+"\"><i class=\"fa fa-circle\"></i>"
										  +"</div>"
										  +"</div>";
							}else if("0".equals(data.get("status")) && (i+1) == workflowExecuteList.size()){
								auditFlow += "<div class=\"timeline-entry-inner\">"
										  +"<div style=\"-webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg);border-color:#33485c;\" class=\"timeline-icon bg-"+color+"\"><i class=\"fa fa-circle\"></i>"
										  +"</div>"
										  +"</div>";
							}
					auditFlow +="</article>";
			}
		}else{
			auditFlow +="<div style=\"text-align: center;\"><span>管理员尚未审核，请耐心等待.....</span><div>";
		}
		/**
		 * end
		 */
		ModelAndView view = new ModelAndView();
		view.addObject("classesEn", classesEn);
		view.addObject("classesId", classesId);
		view.addObject("idString", dynamicDataId);
		view.addObject("headline", headline);
		view.addObject("describe", describe);
		view.addObject("dataProperties", dataProperties);
		view.addObject("data", data);
		view.addObject("status", data.get("status"));
		view.addObject("submitUserId", data.get("submit_user_id"));
		//view.addObject("DictItem", DictItem);
		view.addObject("resultString", arrList);
		view.addObject("dataType", dataType);
		view.addObject("dictsMap", dictsMap);
		view.addObject("dicValue", dicNameEn);
		view.addObject("uploadPath", uploadPath);
		view.addObject("objectProperty", objectProperty);
		view.addObject("objectPropertyClasses", objectPropertyClasses);
		view.addObject("adjunctPath", adjunctPath);
		view.addObject("multiList", multiList);
		view.addObject("picturePath", picturePath);
		view.addObject("screenContent", select);
		view.addObject("roleName", roleName);
		view.addObject("databaseName", databaseName);
		view.addObject("chartName", chartName);
		view.addObject("audit", audit);
		view.addObject("auditFlow", auditFlow);
		view.setViewName("/modules/repository/knowledge_edit_data_detail_update");
		return view;
	}
		
	/**
	 * 修改 方法
	 * zhongfeng
	 * 2016.9.12
	 */
	
	@RequestMapping("knowledge-edit-data-detail-update-method.html")
	public ModelAndView toKnowledgeEditDataClassDetailUpdate(HttpServletRequest request)throws Exception {
		// 三级。如矿石等
		String classesEn = request.getParameter("classesEn");
		String classesId = request.getParameter("classesId");
		String idString = request.getParameter("idString");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");
		String screenContent = request.getParameter("screenContent");
		Classes classes = publicService.findClasses(Integer.parseInt(classesId));
		List<DataProperty> dataProperties = publicService.getDataProperty(classes);
		//获取服务器地址
		 String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		Integer departmentid =(Integer) request.getSession().getAttribute("userid");
		User user = publicService.findUser(departmentid);
		Map<String, Object> aDynamicData = null;
		if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
			aDynamicData =dynamicService.findDynamicData(classesEn, idString,databaseName,chartName);
		}else{
			aDynamicData =dynamicService.findDynamicData(classesEn, idString);
		}
		HashMap<String, Object> data = new HashMap<String, Object>();
		Map<String,Object> conditions = null;
		int shouJi=0;
		for (DataProperty dp : dataProperties) {
			String dataKey = "";
			String dataValue = "";
			if (dp.getAdminDetailShow().equals("1")) {
				dataKey = dp.getNameEn();
				dataValue = request.getParameter(dataKey);
				if(classesEn.equals("ke_hu_zi_liao")){
					if(dataKey.equals("shou_ji")){
						if(!dataValue.equals(aDynamicData.get("shou_ji"))){
							if(dataValue != null && !"".equals(dataValue)){
								conditions = new LinkedHashMap<String, Object>();
								conditions.put("=shou_ji", dataValue);
								long count = 0;
								if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
									count = dynamicService.getDynamicCount(classesEn, conditions,databaseName,chartName);
								}else{
									count = dynamicService.getDynamicCount(classesEn, conditions);
								}
								if(count != 0){
									shouJi=1;
									break;
								}
							}
						}
					}
				}
				//data.put(RenameUtils.UpperCaseFirstLetterLower(dataKey), dataValue);
				if(dp.getDataTypeId() == 14 && dataValue.length()<32){
					dataValue = MD5.convert(dataValue);
				}
				if(dp.getDataTypeId() == 5 || dp.getDataTypeId() == 6 || dp.getDataTypeId() == 8 || dp.getDataTypeId() == 16|| dp.getDataTypeId() == 17|| dp.getDataTypeId() == 24|| dp.getDataTypeId() == 25|| dp.getDataTypeId() == 26|| dp.getDataTypeId() == 27){
					if(dataValue != null && !"".equals(dataValue)){
						dataValue = dataValue.replaceAll(uploadPath, "/");
					}
				}
				data.put(dataKey, dataValue);
			}
		}
			String updateUserId = departmentid.toString();
			String status = "0";
			Double version = Double.valueOf(aDynamicData.get("version").toString()) +1;
			String updateTime = DateUtils.getDateTime();
			String dataSource = "1";
			//是否启用工作流
			Workflow workflow = null;
			WorkflowNode workflowNode = null;
			HashMap<String, Object> queryWorkflowParams = new HashMap<String, Object>();
			queryWorkflowParams.put("=,classes_en", classesEn);
			List<Workflow> workflowList = publicService.getWorkflow(queryWorkflowParams, 1, 1);
			if(null != workflowList && workflowList.size()>0){
				workflow = workflowList.get(0);
				if(workflow.getStatus() == 1){
					status = "3";
					HashMap<String, Object> queryWorkflowNodeParams = new HashMap<String, Object>();
					queryWorkflowNodeParams.put("=,workflow_id", workflow.getId());
					queryWorkflowNodeParams.put("=,sort", 1);
					List<WorkflowNode> workflowNodeList = publicService.getWorkflowNode(queryWorkflowNodeParams, 1, 1);
					if(null != workflowNodeList && workflowNodeList.size()>0){
						workflowNode = workflowNodeList.get(0);
						HashMap<String, Object> queryUserParams = new HashMap<String, Object>();
						queryUserParams.put("=,username", workflowNode.getExecutor());
						List<User> userList= publicService.getUser(queryUserParams, 1, 1);
						if(null != userList && userList.size()>0){
							data.put("submit_user_id", userList.get(0).getId());
						}
					}
				}
			}
			if (shouJi != 1) {
				int logTime=0;
			    try {
			    	if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
			    		dynamicService.editDynamicData(classesEn, data, updateTime, updateUserId, status, version.toString(), idString,databaseName,chartName);
			    	}else{
			    		dynamicService.editDynamicData(classesEn, data, updateTime, updateUserId, status, version.toString(), idString);
			    	}
			    	 //获取服务器地址
					String saveVersion = XxlConfClient.get("dal.store.is.version", "");
			    	if("true".equals(saveVersion)){
			    		dynamicService.addDynamicDataVersion(classesEn, data, updateTime,updateUserId, status, version.toString(), classesId, dataSource, idString);
			    	}
			    	//dynamicService.submitDynamicData(classesEn, updateTime,updateUserId, idString);
				} catch (Exception e) {
					this.log(user.getId(), "knowledge_data", classesId, idString, "【"+user.getNickname()+"】【修改】知识【"+classes.getNameZh()+"】库ID为：【"+idString+"】的数据失败！请检查参数是否正确！", 1);
					logTime=1;
					e.printStackTrace();
				}
			    if(logTime==0){
			    	this.log(user.getId(), "knowledge_data", classesId, idString, "【"+user.getNickname()+"】【修改】知识【"+classes.getNameZh()+"】库ID为：【"+idString+"】的数据成功！", 0);
			    }
			}
			ModelAndView view = new ModelAndView();
			view.addObject("classesEn", classesEn);
			view.addObject("classesId", classesId);
			view.addObject("id", idString);
			view.addObject("databaseName", databaseName);
			view.addObject("chartName", chartName);
			String[] screen1 = screenContent.split("&");
			for (int i = 0; i < screen1.length; i++) {
				if(!"".equals(screen1[i]) && screen1[i] !=null){
					String[] screen2 =screen1[i].split("=");
					if(!"id".equals(screen2[0])){
						view.addObject(screen2[0], screen2[1]);
					}
				}
			}
			//?classesEn="+classesEn+"&classesId="+classesId+"&id="+idString+screenContent
			view.setViewName("redirect:/show-edit-data-detail-update.html");
			return view;

	}
	
	/**
	 * 禁用
	 * zhongfeng
	 * 2016.9.12
	 */
	
	@RequestMapping("knowledge-edit-data-detail-forbidden-method.html")
	public ModelAndView toKnowledgeEditDataClassDetailforbidden(HttpServletRequest request) {
		// 三级。如矿石等
		String classesEn = request.getParameter("classesEn");
		String classesId = request.getParameter("classesId");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");;
		String id = request.getParameter("id");
		String status = request.getParameter("status");
		
		Classes classes = publicService.findClasses(Integer.parseInt(classesId));
		List<DataProperty> dataProperties = publicService.getDataProperty(classes);
		
		/*Cookie[] cookies = request.getCookies();
		String userid="";
		for (int i = 1; i < cookies.length; i++) {
			if("userId".equals(cookies[i].getName())){
				userid= cookies[i].getValue();
			}
		}
		int lg = Integer.parseInt(userid);*/
		Integer departmentid =(Integer) request.getSession().getAttribute("userid");
		
		//User aUser = publicService.findUser(userid);
		
		Classes aClasses = publicService.findClasses(Integer.parseInt(classesId));
		Map<String, Object> dynamicData= null;
		if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
			dynamicData=dynamicService.findDynamicData(classesEn, id,databaseName,chartName);
		}else{
			dynamicData=dynamicService.findDynamicData(classesEn, id);
		}
		
		dynamicData.remove("update_time");
		dynamicData.remove("update_user_id");
		dynamicData.remove("status");
		dynamicData.remove("version");
		dynamicData.remove("id");
		//dynamicData.remove("createTime");
		//dynamicData.remove("submitTime");
		//dynamicData.remove("createUserId");
		//dynamicData.remove("submitUserId");
		//dynamicData.remove("dataSource");
		//dynamicData.remove("classesId");
		//dynamicData.remove("updateOrgId");
		//dynamicData.remove("createOrgId");
		//dynamicData.remove("submitOrgId");
		
			String updateUserId = departmentid.toString();
			String version = "1.0";
			String updateTime = DateUtils.getDateTime();
			if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
				dynamicService.editDynamicData(classesEn, dynamicData, updateTime, updateUserId, status, version, id,databaseName,chartName);
			}else{
				dynamicService.editDynamicData(classesEn, dynamicData, updateTime, updateUserId, status, version, id);
			}
			//dynamicService.submitDynamicData(classesEn, updateTime,updateUserId, id);
			ModelAndView view = new ModelAndView();
			view.addObject("classesEn", classesEn);
			view.addObject("classesId", classesId);
			view.setViewName("redirect:/show-edit-data-list.html");
			return view;

	}
	
	/**
	 * 删除 方法
	 * zhongfeng
	 * 2016.9.12
	 */
	@RequestMapping("knowledgeEditDataDetailDeteleMethod")
	public void toKnowledgeEditDataClassDetailDetele(HttpServletRequest request,HttpServletResponse response)throws Exception {
		// 三级。如矿石等
		String classesEn = request.getParameter("classesEn");
		String classesId = request.getParameter("classesId");
		String idString = request.getParameter("id");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");
		
		Integer departmentid =(Integer) request.getSession().getAttribute("userid");
		User user = publicService.findUser(departmentid);
		Classes classes = publicService.findClasses(Integer.parseInt(classesId));
		Map<String, Object>  aDynamicData= null;
		if(null != chartName && !"".equals(chartName)){
			aDynamicData=dynamicService.findDynamicData(classesEn, idString,databaseName,chartName);
		}else{
			aDynamicData=dynamicService.findDynamicData(classesEn, idString);
		}
		
		int logTime=0;
		try {
			if(null != chartName && !"".equals(chartName)){
				dynamicService.deleteDynamicData(classesEn, aDynamicData,databaseName,chartName);
			}else{
				dynamicService.deleteDynamicData(classesEn, aDynamicData);
			}
			String [] ids =new String[1];
			ids[0]=idString; 
			//dynamicService.deleteIndex(ids);
		} catch (Exception e) {
			this.log(user.getId(), "knowledge_data", classesId, idString, "【"+user.getNickname()+"】【删除】知识【"+classes.getNameZh()+"】库ID为：【"+idString+"】的数据失败！请检查数据是否存在！", 1);
			logTime=1;
			e.printStackTrace();
		}
		if(logTime==0){
			this.log(user.getId(), "knowledge_data", classesId, idString, "【"+user.getNickname()+"】【删除】知识【"+classes.getNameZh()+"】库ID为：【"+idString+"】的数据成功！", 0);
			List<ObjectProperty> objectPropertyList = publicService.getObjectProperty(classes);
			for (int i = 0; i < objectPropertyList.size(); i++) {
				ObjectProperty objectProperty = objectPropertyList.get(i);
				int count = dynamicService.getDynamicObjectDataCount(classesEn, idString, null, objectProperty.getId()).intValue();
				List<Map<String, Object>> DynamicObjectDataList = dynamicService.getDynamicObjectData(classesEn, idString,null, objectProperty.getId(), 0, count);
				for (int j = 0; j < DynamicObjectDataList.size(); j++) {
					Map<String, Object> dynamicObjectData = DynamicObjectDataList.get(j);
					dynamicService.deleteDynamicObjectData(classesEn, dynamicObjectData.get("id").toString(), objectProperty.getId());
				}
			}
		}
		LinkedHashMap<String, Object> returns = new LinkedHashMap<String, Object>();
		returns.put("data", logTime);
		String result = formatToJson(returns);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	/**
	 * 查看版本
	 * zhongfeng
	 * 2017年11月14日18:34:40
	 */
	@RequestMapping("queryknowledgeVersions")
	public void queryknowledgeVersions(HttpServletRequest request,HttpServletResponse response)throws Exception {
		String knowledgeVersionsId = request.getParameter("knowledgeVersionsId");
		String classesEn = request.getParameter("classesEn");
		String curr = request.getParameter("curr");
		Map<String,Object> conditions = new HashMap<String, Object>();
		List<Map<String,Object>> list = dynamicService.getDynamicDataVersion(classesEn, knowledgeVersionsId, conditions, Integer.parseInt(curr), 10);
		List<Map<String,Object>> data = new ArrayList<Map<String,Object>>();
		for (int i = 0; i < list.size(); i++) {
			Map<String,Object> mp = list.get(i);
			String updateUserId = mp.get("update_user_id").toString();
			User user = publicService.findUser(Integer.parseInt(updateUserId));
			if(null != user){
				mp.put("update_user_id", user.getNickname());
			}else{
				mp.put("update_user_id", "");
			}
			/*String classesId = mp.get("classes_id").toString();
			Classes classes = publicService.findClasses(Integer.parseInt(classesId));
			mp.put("classesEn", classes.getNameEn());*/
			data.add(mp);
		}
		long count = dynamicService.getDynamicDataVersionCount(classesEn, knowledgeVersionsId, conditions);
		LinkedHashMap<String, Object> returns = new LinkedHashMap<String, Object>();
		returns.put("data", data);
		returns.put("count", count);
		returns.put("page", (int)Math.ceil(Double.valueOf(count)/10));
		String result = formatToJson(returns);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	
	/**
	 * 版本-详情
	 * zhongfeng
	 * 2016.10.26
	 */
	@RequestMapping("queryknowledgeVersionsDetails")
	public ModelAndView queryknowledgeVersionsDetails(HttpServletRequest request,HttpServletResponse response) throws Exception {
		// 三级。如矿石等
		String id = request.getParameter("id");
		int classesId = Integer.parseInt(request.getParameter("classesId"));
		
		Classes classes = publicService.findClasses(classesId);
		// 标题
		String headline= classes.getNameZh();
		// 描述
		String describe = classes.getDescription();
		List<DataProperty> dataProperties = publicService.getDataProperty(classes);
		List<DataType> dataType = publicService.getDataType();
		Map<String, Object> data = dynamicService.findDynamicDataVersion(classes.getNameEn(),id);
		HashMap<String, Object> picturePath =  new LinkedHashMap<String, Object>();
		 //获取服务器地址
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		 String adjunctPath =  request.getContextPath() + "/adjunct/";
		//字典
		 List<Map<String, Object>> arrList = new ArrayList<Map<String,Object>>();
		 List<Map<Object, Object>> dicNameEn = new ArrayList<Map<Object,Object>>();
		 Map<String, Object> multiList = new LinkedHashMap<String, Object>();
		//List<DictItem> DictItem =new ArrayList<DictItem>();
		 Map<Integer, Integer> dictsMap = new HashMap<Integer, Integer>();
			for(DataProperty dp : dataProperties){
				dp.setNameEn(dp.getNameEn());
				if(null == dp.getFormValidationRegulation()){
					dp.setFormValidationRegulation("");
				}
				Integer dataTypeId= dp.getDataTypeId();
				Integer dictId=dp.getDictId();
				if(dictId != 0){
					Dict dicts = publicService.findDict(dictId);
					dictsMap.put(dp.getDictId(), dicts.getDictType());
					if(dicts.getDictType()==2){
						Map<Object, Object> dicNameEnMap = new HashMap<Object, Object>();
						dicNameEnMap.put("dictDpId", dp.getNameEn());
						dicNameEn.add(dicNameEnMap);
					}
					Dict dict = new Dict();
					dict.setId(dictId);
					List<DictItem> dictItem = publicService.getDictItem(dict);
					for(DictItem dic : dictItem){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("dpid", dp.getId());
						map.put("dicid", dic.getId());
						map.put("nameZh", dic.getNameZh());
						map.put("value", dic.getValue());
						arrList.add(map);
					}
						String multis = data.get(dp.getNameEn()).toString();
						String multiname="";
						if(multis!=null && !"".equals(multis)){
							String [] multimap = multis.split(",");
							for (int i = 0; i < multimap.length; i++) {
								HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
								queryParams.put("=,dict_id", dp.getDictId());
								queryParams.put("=,value", multimap[i]);
								List<DictItem> aDictItems =publicService.getDictItem(queryParams, 1, publicService.getDictItemCount(queryParams));
								if(aDictItems.size()>0 ){
									DictItem aDictItem=aDictItems.get(0);
									multiname += aDictItem.getNameZh()+",";
								}
							}
							if(!"".equals(multiname) && multiname != null){
								multiname = multiname.substring(0, multiname.length()-1);
								multiList.put(dp.getNameEn(), multiname);
							}
						}
				}
				//dp.setDataType(publicService.findDataType(dataTypeId));
				
				if(dp.getDataTypeId() != null && dp.getDataTypeId()==16){
					String wenjian = (String) data.get(dp.getNameEn());
					if(wenjian != null){
						String [] wenjiansz =wenjian.split("%");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						data.put(dp.getNameEn(), danwenjian);
						picturePath.put(dp.getNameEn(), wenjian);
					}
				}
				if(dp.getDataTypeId() == 5 || dp.getDataTypeId() == 6 ){
					String path = (String) data.get(dp.getNameEn());
					if(path != null && !"".equals(path)){
						String url = CommonUrl.addPrefixPath("src", path, uploadPath);
						data.put(dp.getNameEn(),url);
					}
				}
				if(dp.getDataTypeId() != null && dp.getDataTypeId()==17 ){
					String wenjian = (String) data.get(dp.getNameEn());
					if(wenjian != null){
						String [] wenjiansz =wenjian.split("%");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						data.put(dp.getNameEn(), danwenjian);
						picturePath.put(dp.getNameEn(), wenjian);
					}
				}
			}
		for (int i = 0; i < dicNameEn.size(); i++) {
			Map<Object, Object> dic =dicNameEn.get(i);
			dic.put("jieguoji", data.get(dic.get("dictDpId")));
			
		}
		
		ModelAndView view = new ModelAndView();
		view.addObject("classesEn", classes.getNameEn());
		view.addObject("classesId", classesId);
		view.addObject("idString", id);
		view.addObject("headline", headline);
		view.addObject("describe", describe);
		view.addObject("dataProperties", dataProperties);
		view.addObject("dictsMap", dictsMap);
		view.addObject("dataType", dataType);
		view.addObject("data", data);
		view.addObject("dicNameEn", dicNameEn);
		view.addObject("dicValue", dicNameEn);
		view.addObject("picturePath", picturePath);
		view.addObject("resultString", arrList);
		view.addObject("multiList", multiList);
		view.addObject("uploadPath", uploadPath);
		view.addObject("adjunctPath", adjunctPath);
		view.setViewName("/modules/repository/knowledge_edit_data_queryrelevance");
		return view;
	}
	//版本恢复
	@RequestMapping("knowledgeVersionsRestore")
	public void knowledgeVersionsRestore(HttpServletRequest request,HttpServletResponse response)throws Exception {
		String versionsClassesId = request.getParameter("versionsClassesId");
		String VersionsDetailsId = request.getParameter("VersionsDetailsId");
		String id = request.getParameter("knowledgeId");

		Classes classes = publicService.findClasses(Integer.parseInt(versionsClassesId));
		
		Map<String, Object> knowledgedata = dynamicService.findDynamicData(classes.getNameEn(), id);
		Map<String, Object> Versionsdata = dynamicService.findDynamicDataVersion(classes.getNameEn(),VersionsDetailsId);
		
		String create_user_id = knowledgedata.get("create_user_id").toString();
		String create_time = knowledgedata.get("create_time").toString();
		String submit_time = knowledgedata.get("submit_time").toString();
		String create_org_id = knowledgedata.get("create_org_id").toString();
		String submit_org_id = knowledgedata.get("submit_org_id").toString();
		String submit_user_id = knowledgedata.get("submit_user_id").toString();
		
		String version = Versionsdata.get("version").toString();
		String status = Versionsdata.get("status").toString();
		String update_time = Versionsdata.get("update_time").toString();
		String update_user_id = Versionsdata.get("update_user_id").toString();
		Versionsdata.remove("version");
		Versionsdata.remove("status");
		Versionsdata.remove("update_time");
		Versionsdata.remove("update_user_id");
		Versionsdata.remove("_id");
		Versionsdata.remove("id");
		Versionsdata.remove("source_data_id");
		Versionsdata.put("create_user_id", create_user_id);
		Versionsdata.put("create_time", create_time);
		Versionsdata.put("submit_time", submit_time);
		Versionsdata.put("create_org_id", create_org_id);
		Versionsdata.put("submit_org_id", submit_org_id);
		Versionsdata.put("submit_user_id", submit_user_id);
		LinkedHashMap<String, Object> returns = new LinkedHashMap<String, Object>();
		try {
			dynamicService.editDynamicData(classes.getNameEn(), Versionsdata, update_time, update_user_id, status, version, id);
			returns.put("data", "yes");
		} catch (Exception e) {
			returns.put("data", "no");
		}
		String result = formatToJson(returns);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
		
	//知识加工 批量删除
	@RequestMapping("deleteknowledgeAll")
	public void deleteknowledgeAll(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String[] classesIds =request.getParameterValues("ids");
		String classesEn = request.getParameter("classesEn");
		String classesId = request.getParameter("classesId");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");
		Integer departmentid =(Integer) request.getSession().getAttribute("userid");
		User user = publicService.findUser(departmentid);
		Classes classes = publicService.findClasses(Integer.parseInt(classesId));
		int returns=0;
		for (int i = 0; i < classesIds.length; i++) {
			Map<String, Object>  aDynamicData= null;
			if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
				aDynamicData=dynamicService.findDynamicData(classesEn, classesIds[i],databaseName,chartName);
			}else{
				aDynamicData=dynamicService.findDynamicData(classesEn, classesIds[i]);
			}
			int logTime=0;
			try {
				if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
					dynamicService.deleteDynamicData(classesEn, aDynamicData,databaseName,chartName);
				}else{
					dynamicService.deleteDynamicData(classesEn, aDynamicData);
				}
				String [] ids =new String[1];
				ids[0]=classesIds[i]; 
				//dynamicService.deleteIndex(ids);
			} catch (Exception e) {
				this.log(user.getId(), "knowledge_data", classesId, classesIds[i], "【"+user.getNickname()+"】【删除】知识【"+classes.getNameZh()+"】库ID为：【"+classesIds[i]+"】的数据失败！请检查数据是否存在！", 1);
				logTime=1;
				returns=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "knowledge_data", classesId, classesIds[i], "【"+user.getNickname()+"】【删除】知识【"+classes.getNameZh()+"】库ID为：【"+classesIds[i]+"】的数据成功！", 0);
				
			}
		}
		String result = formatToJson(returns);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}
	
		//知识加工 重新分配
		@RequestMapping("uploadanewAllot")
		public void uploadAnewAllot(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String[] users =request.getParameterValues("user");
			String[] values =request.getParameterValues("value");
			String classesEn = request.getParameter("classesEn");
			String databaseName = request.getParameter("databaseName");
			String chartName = request.getParameter("chartName");
			int consequence=0;
			for (int i = 0; i < values.length; i++) {
				/*HashMap<String, Object> dynamicData=baseService.findDynamicData(classesEn, values[i]);
				String id = dynamicData.get("id").toString();
				dynamicData.remove("updateTime");
				dynamicData.remove("updateUserId");
				dynamicData.remove("status");
				dynamicData.remove("version");
				dynamicData.remove("id");
				dynamicData.remove("createTime");
				dynamicData.remove("submitTime");
				dynamicData.remove("createUserId");
				dynamicData.remove("submitUserId");
				dynamicData.remove("dataSource");
				dynamicData.remove("classesId");
				dynamicData.remove("submitOrgId");
				dynamicData.remove("createOrgId");
				dynamicData.remove("updateOrgId");
				dynamicData.put("createUserId", users[0]);
				*/
				Integer departmentid =(Integer) request.getSession().getAttribute("userid");
				
				String updateUserId = departmentid.toString();
				String status = "0";
				String version = "1.0";
				String updateTime = DateUtils.getDateTime();
			    try {
			    	String userid = users[0];
			    	String valueid = values[i];
			    	//System.out.println(userid);
			    //	System.out.println(valueid);
			    	if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
			    		dynamicService.editDynamicDataCreateUser(classesEn, valueid, userid,databaseName,chartName);
			    	}else{
			    		dynamicService.editDynamicDataCreateUser(classesEn, valueid, userid);
			    	}
			    	//dynamicService.submitDynamicData(classesEn, updateTime,updateUserId, valueid);
				} catch (Exception e) {
					consequence=1;
				}
			}
			
		    
			String result = formatToJson(consequence);
			super.pringWriterToPage(result.toString(), "application/json", response);

		}
	
		//图形化知识库管理
		@RequestMapping("KnowledgeDataProperty")
		public void toKnowledgeDataProperty(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String id = request.getParameter("lid");
			String classname = request.getParameter("classname");
			Classes Classes1 = publicService.findClasses(Integer.parseInt(id));
			List<DataProperty> list1 = publicService.getDataProperty(Classes1);
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			for (int i = 0; i < list1.size(); i++) {
				DataProperty DataProperty1 = list1.get(i);
				mp = new LinkedHashMap<String, Object>();
				mp.put("value",(int)(1+Math.random()*(10-1+1)));
				mp.put("category", 1);
				mp.put("name", DataProperty1.getNameZh());
				mp.put("source", DataProperty1.getNameZh());
				mp.put("target", classname);
				mp.put("weight", (int)(1+Math.random()*(2-1+1)));
				r.add(mp);
			}
			List<ObjectProperty> objectProperty =publicService.getObjectProperty(Classes1);
			for (int i = 0; i < objectProperty.size(); i++) {
				ObjectProperty op = objectProperty.get(i);
				mp = new LinkedHashMap<String, Object>();
				mp.put("value",(int)(1+Math.random()*(10-1+1)));
				mp.put("category", 2);
				mp.put("name", op.getNameZh());
				mp.put("source", op.getNameZh());
				mp.put("target", classname);
				mp.put("weight", (int)(1+Math.random()*(2-1+1)));
				r.add(mp);
				if(op.getRelevanceClassesId() != null){
					Classes Classes = publicService.findClasses(op.getRelevanceClassesId());
						mp = new LinkedHashMap<String, Object>();
						mp.put("value",(int)(1+Math.random()*(10-1+1)));
						mp.put("category", 12);
						mp.put("name", Classes.getNameZh());
						mp.put("source", Classes.getNameZh());
						mp.put("target", op.getNameZh());
						mp.put("weight", (int)(1+Math.random()*(2-1+1)));
						r.add(mp);
					List<DataProperty> dataPropertyList = publicService.getDataProperty(Classes);
					for(DataProperty l: dataPropertyList){
						String[] classess =op.getRelevanceClassFields().split(",");
						for(int j=0;j<classess.length;j++ ){
							if(l.getId() == Integer.parseInt(classess[j])){
								mp = new LinkedHashMap<String, Object>();
								mp.put("value",(int)(1+Math.random()*(10-1+1)));
								mp.put("category", 11);
								mp.put("name", l.getNameZh());
								mp.put("source", l.getNameZh());
								mp.put("target", Classes.getNameZh());
								mp.put("weight", (int)(1+Math.random()*(2-1+1)));
								r.add(mp);
							}
						}
					}
				}
			}
			
			LinkedHashMap<String, Object> classmp = new LinkedHashMap<String, Object>();
			classmp.put("category", 0);
			classmp.put("name", classname);
			classmp.put("value", 10);
			classmp.put("label", classname);
			r.add(classmp);
			String result = formatToJson(r);
			super.pringWriterToPage(result.toString(), "application/json", response);

		}
		

		// 图形化知识加工
		@RequestMapping("knowledgeEditDataDetailUpdate")
		public void toknowledgeEditDataDetailUpdate(HttpServletRequest request,
				HttpServletResponse response) throws Exception {
			String classesEn = request.getParameter("classname");
			String classesId = request.getParameter("classid");
			String dynamicDataId = request.getParameter("id");
			String databaseName = request.getParameter("databaseName");
			String chartName = request.getParameter("chartName");
		
			Classes classes = publicService.findClasses(Integer.parseInt(classesId));
			// 标题
			String headline= classes.getNameZh();
			//描述
			String  description= classes.getDescription();
			
		//	List<ObjectProperty> objectProperty = publicService.getObjectProperty(classes);
			List<DataProperty> dataProperties = publicService.getDataProperty(classes);
			List<DataType> dataType =publicService.getDataType();
			/*for(DataProperty dp : dataProperties){
				Integer dataTypeId= dp.getDataTypeId();
				dp.setDataType(publicService.findDataType(dataTypeId));
			}*/
			Map<String, Object> data = null;
			if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
				data = dynamicService.findDynamicData(classesEn,dynamicDataId,databaseName,chartName);
			}else{
				data = dynamicService.findDynamicData(classesEn,dynamicDataId);
			}
			//获取服务器地址
			String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
			 String adjunctPath =  request.getContextPath() + "/adjunct/";
			//字典
			 
			List<Map<String, Object>> arrList = new ArrayList<Map<String,Object>>();
				for(DataProperty dp : dataProperties){
					Integer dataTypeId= dp.getDataTypeId();
					Integer dictId=dp.getDictId();
					if(dictId != 0){
						Dict dicts = publicService.findDict(dictId);
						Dict dict = new Dict();
						dict.setId(dictId);
						List<DictItem> dictItem = publicService.getDictItem(dict);
						for(DictItem dic : dictItem){
							Map<String, Object> map = new HashMap<String, Object>();
							map.put("dpid", dp.getId());
							map.put("dicid", dic.getId());
							map.put("nameZh", dic.getNameZh());
							map.put("value", dic.getValue());
							arrList.add(map);
						}
						//dp.setDict(dicts);
					}
					//dp.setDataType(publicService.findDataType(dataTypeId));
				}
			
				List<DictItem> dictItemList=publicService.getDictItem();
				List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
				LinkedHashMap<String, Object> mp = null;
				for (int i = 0; i < dataProperties.size(); i++) {
					DataProperty DataProperty1 = dataProperties.get(i);
					mp = new LinkedHashMap<String, Object>();
					mp.put("value", (int)(1+Math.random()*(10-1+1)));
					mp.put("category", 1);
					mp.put("name", DataProperty1.getNameZh());
					mp.put("source", DataProperty1.getNameZh());
					mp.put("target", headline);
					mp.put("weight", (int)(1+Math.random()*(2-1+1)));
						if(DataProperty1.getDataTypeId() == 8){
							mp.put("text", "<img src='"+uploadPath+data.get(DataProperty1.getNameEn())+"' width='400px' height='250px' />");
						}else if(DataProperty1.getDataTypeId()== 7){
							for(DictItem dic: dictItemList){
								if(dic.getValue().equals(data.get(DataProperty1.getNameEn())) && dic.getDictId().equals(DataProperty1.getDictId())){
									mp.put("text", dic.getNameZh());
									break;
								}
							}
						}else if(DataProperty1.getDataTypeId() != null && DataProperty1.getDataTypeId() == 17){
							
								String wenjian = (String) data.get(DataProperty1.getNameEn());
								if(wenjian != null){
									String [] wenjiansz =wenjian.split("%");
									String danwenjian = "";
									for (int j = 0; j < wenjiansz.length; j++) {
										if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
											danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
										}
									}
									mp.put("text", danwenjian);
								}
							
						}else if(DataProperty1.getDataTypeId() != null && DataProperty1.getDataTypeId() == 16){
								String wenjian = (String) data.get(DataProperty1.getNameEn());
								if(wenjian != null){
									String [] wenjiansz =wenjian.split("%");
									String danwenjian = "";
									for (int j = 0; j < wenjiansz.length; j++) {
										if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
											danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
										}
									}
									mp.put("text", danwenjian);
							}
						}else{
							mp.put("text", data.get(DataProperty1.getNameEn()));
						}
						
					
					r.add(mp);
				}
				
				List<ObjectProperty> objectProperty =publicService.getObjectProperty(classes);
				for (int i = 0; i < objectProperty.size(); i++) {
					ObjectProperty op = objectProperty.get(i);
					mp = new LinkedHashMap<String, Object>();
					mp.put("value",(int)(1+Math.random()*(10-1+1)));
					mp.put("category", 2);
					mp.put("name", op.getNameZh());
					mp.put("source", op.getNameZh());
					mp.put("target", headline);
					mp.put("weight", (int)(1+Math.random()*(2-1+1)));
					mp.put("show", 1);
					r.add(mp);
					if(op.getRelevanceClassesId() != null){
						Classes Classes = publicService.findClasses(op.getRelevanceClassesId());
							mp = new LinkedHashMap<String, Object>();
							mp.put("value",(int)(1+Math.random()*(10-1+1)));
							mp.put("category", 12);
							mp.put("name", Classes.getNameZh());
							mp.put("source", Classes.getNameZh());
							mp.put("target", op.getNameZh());
							mp.put("weight", (int)(1+Math.random()*(2-1+1)));
							mp.put("show", 1);
							r.add(mp);
							
						List<DataProperty> dataPropertyList = publicService.getDataProperty(Classes);
						for(DataProperty l: dataPropertyList){
							String[] classess =op.getRelevanceClassFields().split(",");
							for(int j=0;j<classess.length;j++ ){
								if(l.getId() == Integer.parseInt(classess[j])&& l.getRelevanceClassShowField().equals("1")){
									mp = new LinkedHashMap<String, Object>();
									mp.put("value",(int)(1+Math.random()*(10-1+1)));
									mp.put("category", 11);
									mp.put("name", l.getNameZh());
									mp.put("source", l.getNameZh());
									mp.put("target", Classes.getNameZh());
									mp.put("weight", (int)(1+Math.random()*(2-1+1)));
									mp.put("show", 1);
									r.add(mp);
								}
							}
						}
					}
				}
				
				
				
				LinkedHashMap<String, Object> classmp = new LinkedHashMap<String, Object>();
				classmp.put("category", 0);
				classmp.put("name", headline);
				classmp.put("value", 0);
				classmp.put("label", headline);
				classmp.put("target", headline);
				classmp.put("text", description);
				r.add(classmp);
				String result = formatToJson(r);
				super.pringWriterToPage(result.toString(), "application/json", response);
				
		}
	
	/*
	 * 知识发布—添加
	 */
	@RequestMapping("knowledge-edit-data-submit-ajax.html")
	public void toknowledgeEditDataSubmitAjax(HttpServletRequest request,HttpServletResponse response)throws Exception {
	
		Integer departmentid =(Integer) request.getSession().getAttribute("departmentid");
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		
		String name =request.getParameter("name");
		String description =request.getParameter("description");
		String classesId =request.getParameter("classesId");
		String isIncrementIndex=request.getParameter("isIncrementIndex");
		String isFullText=request.getParameter("isFullText");
		//User user = publicService.findUser(userid);
		
		DataSubmit dataSubmit = new DataSubmit();
		dataSubmit.setClassesIds(classesId);
		dataSubmit.setCreateUserId(departmentid);
		dataSubmit.setDescription(description);
		dataSubmit.setName(name);
		dataSubmit.setIsIncrementIndex(Integer.parseInt(isIncrementIndex));
		dataSubmit.setIsFullText(Integer.parseInt(isFullText));
		dataSubmit.setStatus(Integer.parseInt("0"));
		
		dataSubmit.setCreateTime((DateUtils.getDateTime()).toString());
		
		/*int logTime=0;*/
		DataSubmit dSubmit=null;
		dSubmit=baseService.saveDataSubmit(dataSubmit);
	/*	try {
			
		} catch (Exception e) {
			this.log(user.getId(), "data", classesId, null, "【"+user.getNickname()+"】【新增】发布的数据失败！请检查数据是否正确！", 1);
			logTime=1;
			e.printStackTrace();
		}
		if(logTime==0){
			this.log(user.getId(), "data", classesId, null, "【"+user.getNickname()+"】【新增】发布ID为：【"+dSubmit.getId()+"】的数据成功！", 0);
		}*/
	}
	
	/*
	 * 知识发布—列表显示
	 */
	@RequestMapping("knowledge-edit-data-submit-list.html")
	public void toknowledgeEditDataSubmitList(HttpServletRequest request,HttpServletResponse response) throws Exception {
		//页数
		int page =Integer.parseInt(request.getParameter("page"));
		//输入内容
		String electText =request.getParameter("electText");
		//字段
		String queryParam =request.getParameter("queryParams");
		
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if(electText != null && !"".equals(electText)){
			queryParams.put("%,"+queryParam, electText);
		}
		queryParams.put("^,create_time", "desc");
		List<DataSubmit> dataSubmitList=null;
		int count=0;
		if(electText.equals("") ){
			long pageCount = publicService.getDataSubmitCount(null);
			count =(int)Math.ceil(Double.valueOf(pageCount)/15);
			dataSubmitList= publicService.getDataSubmit(queryParams, page, 15);
		}else{
			long pageCount = publicService.getDataSubmitCount(queryParams);
			count =(int)Math.ceil(Double.valueOf(pageCount)/15);
			dataSubmitList= publicService.getDataSubmit(queryParams, page, 15);
		}
		
		List<Department> departmentList = publicService.getDepartment();
		List<Classes> classesList = publicService.getClasses();
		
		HashMap<String, Object> listText = new HashMap<String, Object>();
		/*for(DataSubmit dataSubmit:dataSubmitList){
			map =new HashMap<String, Object>();
			Department dm = publicService.findDepartment(dataSubmit.getCreateUserId());
			Classes classes = publicService.findClasses(dataSubmit.getClassesId());
			map.put(dataSubmit.getClassesId().toString(), classes);
			Listmap.add(map);
			map.put(dataSubmit.getCreateUserId().toString(), dm);
			Listmap.add(map);
		}*/
		listText.put("dataSubmitList", dataSubmitList);
		listText.put("count", count);
		listText.put("departmentList", departmentList);
		listText.put("classesList", classesList);
		
		String resultString = formatToJson(listText);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	
	/*
	 * 知识发布—删除
	 */
	@RequestMapping("knowledge-edit-data-submit-detele.html")
	public ModelAndView toknowledgeEditDataSubmitDetele(HttpServletRequest request,HttpServletResponse response) throws Exception {
		//页数
		String id =request.getParameter("id");
		DataSubmit dataSubmit=publicService.findDataSubmit(Integer.parseInt(id));
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		baseService.deleteDataSubmit(dataSubmit);
		/*int logTime=0;
		try {
			
		} catch (Exception e) {
			this.log(user.getId(), "data", dataSubmit.getClassesIds().toString(), dataSubmit.getId().toString(), "【"+user.getNickname()+"】【删除】发布ID为：【"+dataSubmit.getId()+"】的数据失败！请检查数据是否正确！", 1);
			logTime=1;
			e.printStackTrace();
		}
		if(logTime==0){
			this.log(user.getId(), "data", dataSubmit.getClassesIds().toString(), dataSubmit.getId().toString(), "【"+user.getNickname()+"】【删除】发布ID为：【"+dataSubmit.getId()+"】的数据成功！", 0);
		}*/
		
		ModelAndView view = new ModelAndView();
		view.setViewName("redirect:/show-edit-data-submit.html");
		return view;
	}
	
	/*
	 * 知识加工—发布
	 */
	@RequestMapping("knowledge-edit-data-submit-release.html")
	public void toknowledgeEditDataSubmitrelease(HttpServletRequest request,HttpServletResponse response) throws Exception {
		//页数
		String classesEn =request.getParameter("classesEn");
		String id =request.getParameter("id");

		/*Cookie[] cookies = request.getCookies();
		String userid="";
		for (int i = 1; i < cookies.length; i++) {
			if("userId".equals(cookies[i].getName())){
				userid= cookies[i].getValue();
			}
		}*/
		Integer user = (Integer) request.getSession().getAttribute("departmentid");
		
		
		String updateTime = DateUtils.getDateTime();
		
		//baseService.submitDynamicData(classesEn, updateTime, user.toString());
		
		DataSubmit dataSubmit=publicService.findDataSubmit(Integer.parseInt(id));
		int status = 1;
		dataSubmit.setStatus(status);
		
		baseService.editDataSubmit(dataSubmit);
		String resultString = formatToJson(1);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	
	/**
	 * 
	 * 角色
	 */
	
		//查询角色
		@RequestMapping("knowledgeEditDataRoleQuery")
		public void toKnowledgeEditDataRoleQuery(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String queryParam = request.getParameter("queryParams");
			String text = request.getParameter("text");
			HashMap<String, Object> queryParams = new HashMap<String, Object>();
			if(text !=null && !"".equals(text)){
				queryParams.put("%,"+queryParam, text);
			}
			List<Role> role=publicService.getRole(queryParams);
			for(int i=0; i<role.size();i++){
				if(role.get(i).getId() == 1){
					role.remove(i);
				}
			}
			String resultString = formatToJson(role);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		//修改查询角色
		@RequestMapping("knowledgeEditDataRoleEditQuery")
		public void toKnowledgeEditDataRoleEditQuery(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			Role role = publicService.findRole(id);
			LinkedHashMap<String, Object> roleList = new LinkedHashMap<String, Object>();
			roleList.put("id", role.getId());
			roleList.put("name", role.getName());
			roleList.put("description", role.getDescription());
			String resultString = formatToJson(roleList);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		//添加角色
		@RequestMapping("knowledgeEditDataRoleAdd")
		public void toKnowledgeEditDataRoleAdd(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String name =request.getParameter("name");
			String description =request.getParameter("description");
			Role role = new Role();
			role.setName(name);
			role.setDescription(description);
			
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			Role r=null;
			try {
				r = baseService.saveRole(role);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】角色【"+name+"】失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】角色【"+name+"】成功！", 0);
			}
			
			String resultString = formatToJson(r);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		//删除角色
		@RequestMapping("knowledgeEditDataRoleDetele")
		public void toKnowledgeEditDataRoleDelete(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			Role role = publicService.findRole(id);
			
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			try {
				baseService.deleteRole(role);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】角色【"+role.getName()+"】失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】角色【"+role.getName()+"】成功！", 0);
			}
			
			String resultString = formatToJson(1);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		//修改角色
		@RequestMapping("knowledgeEditDataRoleEdit")
		public void toKnowledgeEditDataRoleEdit(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			String name =request.getParameter("name");
			String description =request.getParameter("description");
			Role role = new Role();
			role.setId(id);
			role.setName(name);
			role.setDescription(description);
			role.setDescription(description);
			
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			Role r=null;
			try {
				r = baseService.editRole(role);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】角色【"+role.getName()+"】失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】角色【"+role.getName()+"】成功！", 0);
			}
			
			String resultString = formatToJson(r);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		//查询用户
		@RequestMapping("knowledgeEditDataRoleQueryUser")
		public void toKnowledgeEditDataRoleQueryUser(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String StringId =request.getParameter("id");
			Integer pageSize = Integer.parseInt(request.getParameter("page"));
			String queryParam = request.getParameter("queryParams");
			String text = request.getParameter("text");
			HashMap<String, Object> queryParams = new HashMap<String, Object>();
			if(text !=null && !"".equals(text)){
				queryParams.put("%,"+queryParam, text);
			}
			Integer count = publicService.getUserCount(queryParams);
			int ye = (int) Math.ceil(Double.valueOf(count) / 5);
			
			List<Integer> userList = new ArrayList<Integer>();
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			List<UserRole> userRole= publicService.getUserRole();
				for(UserRole ur : userRole){
					if(StringId != null &&ur.getRoleId() == Integer.parseInt(StringId)){
						userList.add(ur.getUserId());
					}
				}
			List<User> user =publicService.getUser(queryParams, pageSize,5);
			
			for(User u :user){
				mp = new LinkedHashMap<String, Object>();
				for(int ul :userList){
					if(u.getId() == ul){
						mp.put("page", 1);
					}
				}
				Department department =publicService.findDepartment(u.getDepartmentId());
				mp.put("id", u.getId());
				mp.put("name", u.getUsername());
				mp.put("nickname", u.getNickname());
				mp.put("partment", department.getName());
				mp.put("telephone", u.getTelephone());
				mp.put("address", u.getAddress());
				mp.put("email", u.getEmail());
				mp.put("pagination", ye);
				r.add(mp);
				}
			String resultString = formatToJson(r);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		
		//删除用户
		@RequestMapping("knowledgeEditDataDeleteUser")
		public void toKnowledgeEditDataDeleteUser(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			UserRole userRole=publicService.findUserRole(id);
			Role role= publicService.findRole(userRole.getRoleId());
			User u=publicService.findUser(userRole.getUserId());
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			try {
				baseService.deleteUserRole(userRole);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】【"+role.getName()+"】角色下用户【"+u.getUsername()+"】失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】【"+role.getName()+"】角色下用户【"+u.getUsername()+"】成功！", 0);
			}
			
			String resultString = formatToJson(1);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		//删除全部用户
		@RequestMapping("knowledgeEditDataDeleteAllUser")
		public void toKnowledgeEditDataDeleteAllUser(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			List<UserRole> userRole= publicService.getUserRole();
			for(UserRole ur : userRole){
				if(ur.getRoleId() == id){
					int logTime=0;
					User u=publicService.findUser(ur.getUserId());
					Role role= publicService.findRole(ur.getRoleId());
					User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
					try {
						baseService.deleteUserRole(publicService.findUserRole(ur.getId()));
					} catch (Exception e) {
						this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】【"+role.getName()+"】角色下用户【"+u.getUsername()+"】失败！请检查数据是否正确！", 1);
						logTime=1;
						e.printStackTrace();
					}
					if(logTime==0){
						this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】【"+role.getName()+"】角色下用户【"+u.getUsername()+"】成功！", 0);
					}
				}
			}
			String resultString = formatToJson(1);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		//修改用户
		@RequestMapping("knowledgeEditDataAddUser")
		public void toKnowledgeEditDataAddUser(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			String[] button =request.getParameterValues("roleId");
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			
			if(button != null){
				for(int i=0; i<button.length;i++){
					List<UserRole> userRole= publicService.getUserRole();
						int suerroleid =00;
						for(UserRole ur : userRole){
							if(ur.getRoleId() == id && ur.getUserId() == Integer.parseInt(button[i])){
								suerroleid=ur.getId();
							}
						}
						if(suerroleid == 00){
							int logTime=0;
							User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
							UserRole userrole = new UserRole();
							userrole.setUserId(Integer.parseInt(button[i]));
							userrole.setRoleId(id);
							User u=publicService.findUser(Integer.parseInt(button[i]));
							Role role= publicService.findRole(id);
							try {
								baseService.saveUserRole(userrole);
							} catch (Exception e) {
								this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】【"+role.getName()+"】角色下用户【"+u.getUsername()+"】失败！请检查数据是否正确！", 1);
								logTime=1;
								e.printStackTrace();
							}
							if(logTime==0){
								this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】【"+role.getName()+"】角色下用户【"+u.getUsername()+"】成功！", 0);
							}
						}
				}
			}
			List<UserRole> userRole= publicService.getUserRole();
 			List<Integer> userList = new ArrayList<Integer>();
			for(UserRole ur : userRole){
				if(ur.getRoleId() == id){
					userList.add(ur.getUserId());
				}
			}
			for(int usid: userList){
				User user=publicService.findUser(usid);
				mp = new LinkedHashMap<String, Object>();
				for(UserRole ur : userRole){
					if(ur.getUserId() == usid ){
						mp.put("userRoleId", ur.getId());
					}
				}
				mp.put("userId", user.getId());
				mp.put("name", user.getUsername());
				r.add(mp);
			}	
			

			String result = formatToJson(r);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		/**
		 * 用户组
		 */
		//查询用户组
		@RequestMapping("knowledgeEditDataRoleQueryUserGroup")
		public void toKnowledgeEditDataRoleQueryUserGroup(HttpServletResponse response) throws Exception {
			
			List<UserGroup> list1 = publicService.getUserGroup();
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			for (int i = 0; i < list1.size(); i++) {
				UserGroup userGroup = list1.get(i);
				if(userGroup.getId() != 1){
					mp = new LinkedHashMap<String, Object>();
					mp.put("id", userGroup.getId());
					mp.put("name", userGroup.getName());
					mp.put("pId", userGroup.getParentId());
					r.add(mp);
				}
				
			}
			String result = formatToJson(r);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		//用户组查询用户
		@RequestMapping("knowledgeEditDataQueryUser")
		public void toKnowledgeEditDataQueryUser(HttpServletRequest request,HttpServletResponse response) throws Exception {
			
			int id =Integer.parseInt(request.getParameter("id"));
			List<Integer> userList = new ArrayList<Integer>();
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			List<UserRole> userRole= publicService.getUserRole();
				for(UserRole ur : userRole){
					if(ur.getRoleId() == id){
						userList.add(ur.getUserId());
					}
				}
				for(int ul :userList){
					mp = new LinkedHashMap<String, Object>();
					User ur =publicService.findUser(ul);
					mp.put("id", ur.getId());
					mp.put("name", ur.getUsername());
					r.add(mp);
				}
			String resultString = formatToJson(r);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		//用户组查询全部用户
		@RequestMapping("knowledgeEditDataQueryAllUser")
		public void toKnowledgeEditDataQueryAllUser(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			List<Integer> userList = new ArrayList<Integer>();
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			List<UserGroupUser> users= publicService.getUserGroupUser();
				for(UserGroupUser us : users){
					if(us.getUserGroupId() == id){
						userList.add(us.getUserId());
					}
				}
				for(int ul :userList){
					mp = new LinkedHashMap<String, Object>();
					User ur =publicService.findUser(ul);
					if(null != ur){
						mp.put("id", ur.getId());
						mp.put("name", ur.getNickname());
						r.add(mp);
					}
				}
			/*String sourceStr =null;
			List<UserGroupRole> userGroupRole=publicService.getUserGroupRole();
			for(UserGroupRole ugr:userGroupRole){
				if(ugr.getUserGroupId() == id){
					sourceStr = ugr.getRoleIds();
					String[] sourceStrArray = sourceStr.split(":");
					for (int i =0;i< sourceStrArray.length; i++){
						List<UserRole> usrRole = publicService.getUserRole();
						for(UserRole ur :usrRole){
							if(ur.getRoleId() ==Integer.parseInt(sourceStrArray[i])){
								User user =publicService.findUser(ur.getUserId());
								mp = new LinkedHashMap<String, Object>();
								mp.put("id", user.getId());
								mp.put("name", user.getUsername());
								r.add(mp);
							}
						}
					}
				}
			}*/
			String resultString = formatToJson(r);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		//添加用户组
		@RequestMapping("knowledgeEditDataRoleAddUserGroup")
		public void toKnowledgeEditDataRoleAddUserGroup(HttpServletRequest request,HttpServletResponse response) throws Exception {
			
			String name =request.getParameter("name");
			String description =request.getParameter("description");
			int parentId =Integer.parseInt(request.getParameter("parentClassid"));
			UserGroup userGroup = new UserGroup();
			userGroup.setName(name);
			userGroup.setParentId(parentId);
			userGroup.setDescription(description);
			
			UserGroup ugp=null;
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			try {
				ugp = baseService.saveUserGroup(userGroup);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】用户组【"+name+"】失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】用户组【"+name+"】成功！", 0);
			}
			
			String resultString = formatToJson(ugp);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		
		//删除用户组
		@RequestMapping("knowledgeEditDataRoleDeleteUserGroup")
		public void toKnowledgeEditDataRoleDeleteUserGroup(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			int page = 0;
			List<UserGroupUser> userGroupUser =publicService.getUserGroupUser();
			for(UserGroupUser ugu:userGroupUser){
				if(ugu.getUserGroupId() == id){
					page = 1;
				}
			}
			if(page ==0){
				List<UserGroup> userGroup = publicService.getUserGroup();
				for(UserGroup ug :userGroup){
					if(ug.getId() == id){
						List<UserGroupRole> userGroupRole=publicService.getUserGroupRole();
						for(UserGroupRole ugr: userGroupRole){
							if(ugr.getUserGroupId() == id){
								baseService.deleteUserGroupRole(publicService.findUserGroupRole(ugr.getId()));
							}
						}
						int logTime=0;
						User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
						UserGroup uGroup=publicService.findUserGroup(id);
						try {
							baseService.deleteUserGroup(uGroup);
						} catch (Exception e) {
							this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】用户组【"+uGroup.getName()+"】失败！请检查数据是否正确！", 1);
							logTime=1;
							e.printStackTrace();
						}
						if(logTime==0){
							this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】用户组【"+uGroup.getName()+"】成功！", 0);
						}
					}
				}
			}
		
			String resultString = formatToJson(page);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		//查询用户组信息
		@RequestMapping("knowledgeEditDataRoleQueryUserGroupMessage")
		public void toKnowledgeEditDataRoleQueryUserGroupMessage(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			UserGroup userGroup = publicService.findUserGroup(id);
			LinkedHashMap<String, Object> userGroupList = new LinkedHashMap<String, Object>();
			userGroupList.put("id", userGroup.getId());
			userGroupList.put("name", userGroup.getName());
			userGroupList.put("description", userGroup.getDescription());
			userGroupList.put("parentId", userGroup.getParentId());
			
			if(userGroup.getParentId() == 0){
				userGroupList.put("parentName", "根目录");
			}else{
				UserGroup Parent = publicService.findUserGroup(userGroup.getParentId());
				if(Parent.getName().equals(userGroup.getName())){
					userGroupList.put("parentName", "根目录");
				}else{
					userGroupList.put("parentName", Parent.getName());
				}
			}
			
			String resultString = formatToJson(userGroupList);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		
		//修改用户组
		@RequestMapping("knowledgeEditDataRoleEditUserGroup")
		public void toKnowledgeEditDataRoleEditUserGroup(HttpServletRequest request,HttpServletResponse response) throws Exception {
			
			int id =Integer.parseInt(request.getParameter("id"));
			String name =request.getParameter("name");
			String description =request.getParameter("description");
			int parentId =Integer.parseInt(request.getParameter("parentClassid"));
			
			UserGroup userGroup = new UserGroup();
			userGroup.setId(id);	
			userGroup.setName(name);
			userGroup.setDescription(description);
			userGroup.setParentId(parentId);
			
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			UserGroup ug=null;
			try {
				ug = baseService.editUserGroup(userGroup);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】用户组【"+name+"】失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】用户组【"+name+"】成功！", 0);
			}
			
			String resultString = formatToJson(ug);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		

		//查询用户组角色
		@RequestMapping("knowledgeEditDataQueryUserGroupRole")
		public void toKnowledgeEditDataQueryUserGroupRole(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String userGroupId = request.getParameter("id");
			List<HashMap<String, Object>> textList = new ArrayList<HashMap<String, Object>>();
			HashMap<String, Object> roleMap;
			String sourceStr =null;
			List<UserGroupRole> userGroupRole=publicService.getUserGroupRole();
			List<Role> role= publicService.getRole();
			int pags=0;
			if(userGroupId != null){
				int id =Integer.parseInt(userGroupId);
				for(UserGroupRole ugr:userGroupRole){
					if(ugr.getUserGroupId() == id){
						sourceStr = ugr.getRoleIds();
						String[] sourceStrArray = sourceStr.split(":");
						for(Role r:role){
						if(r.getId() != 1){
							roleMap = new LinkedHashMap<String, Object>();
								for (int i =0;i< sourceStrArray.length; i++){
									if(!sourceStrArray[i].equals("")){
										if(r.getId() == Integer.parseInt(sourceStrArray[i])){
											roleMap.put("pitch", 1);
									}
								}
							}
							roleMap.put("roleId", r.getId());
							roleMap.put("roleName", r.getName());
							textList.add(roleMap);
						}
						pags =1;
						}
					}
				}
			}
			if(userGroupId == null){
				for(Role r:role){
					if(r.getId() != 1){
						roleMap = new LinkedHashMap<String, Object>();
						roleMap.put("roleId", r.getId());
						roleMap.put("roleName", r.getName());
						textList.add(roleMap);
					}
					
				}
				pags = 1;
			}
				if(pags == 0){
					for(Role r:role){
						if(r.getId() != 1){
							roleMap = new LinkedHashMap<String, Object>();
							roleMap.put("roleId", r.getId());
							roleMap.put("roleName", r.getName());
							textList.add(roleMap);
						}
					}
					pags = 1;
				}
			String resultString = formatToJson(textList);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		
		//修改用户组角色
		@RequestMapping("knowledgeEditDataEditUserGroupRole")
		public void toKnowledgeEditDataEditUserGroupRole(HttpServletRequest request,HttpServletResponse response) throws Exception {
			
			int userGroupId =Integer.parseInt(request.getParameter("id"));
			String[] roleId =request.getParameterValues("roleId");
			String roleids="";
			int id = 00;
			if(roleId != null){
				for (int i = 0; i < roleId.length; i++) {
					roleids += roleId[i]+":";
				}
			}
			
				List<UserGroupUser> userGroupUser= publicService.getUserGroupUser();
				for( UserGroupUser ugu:userGroupUser){
					if(ugu.getUserGroupId() == userGroupId ){
						List<UserRole> userList=publicService.getUserRole();
						for(UserRole ul :userList){
							if(ul.getUserId() == ugu.getUserId()){
								baseService.deleteUserRole(publicService.findUserRole(ul.getId()));
							}
						}
						if(roleId != null){
							for (int i = 0; i < roleId.length; i++) {
								UserRole userRole = new UserRole();
								userRole.setRoleId(Integer.parseInt(roleId[i]));
								userRole.setUserId(ugu.getUserId());
								baseService.saveUserRole(userRole);
							}
						}
					}
				}
			List<UserGroupRole> userGroupRoleList=publicService.getUserGroupRole();
				for(UserGroupRole ugr:userGroupRoleList){
					if(ugr.getUserGroupId() == userGroupId){
						id=ugr.getId();
					}
				}
			UserGroupRole userGroupRole = new UserGroupRole();
			UserGroupRole ugrs =null;
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			UserGroup uGroup=publicService.findUserGroup(userGroupId);
			try {
				if(id==00){
					userGroupRole.setRoleIds(roleids);
					userGroupRole.setUserGroupId(userGroupId);
					ugrs=baseService.saveUserGroupRole(userGroupRole);
				}else{
					userGroupRole.setId(id);
					userGroupRole.setRoleIds(roleids);
					userGroupRole.setUserGroupId(userGroupId);
					ugrs =baseService.editUserGroup(userGroupRole);
				}
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】用户组【"+uGroup.getName()+"】下角色失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】用户组【"+uGroup.getName()+"】下角色成功！", 0);
			}
			
			
			String resultString = formatToJson(ugrs);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		
		/**
		 * 部门
		 * @param response
		 * @throws Exception
		 */
		
		//查询部门
		@RequestMapping("knowledgeEditDataQueryDepartment")
		public void toKnowledgeEditDataQueryDepartment(HttpServletResponse response) throws Exception {
			
			List<Department> department = publicService.getDepartment();
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			for (int i = 0; i < department.size(); i++) {
				Department dep = department.get(i);
				if(dep.getId() != 1){
					mp = new LinkedHashMap<String, Object>();
					mp.put("id", dep.getId());
					mp.put("name", dep.getName());
					mp.put("pId", dep.getParentId());
					r.add(mp);
				}
			}
			String result = formatToJson(r);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		//查询部门信息
		@RequestMapping("knowledgeEditDataRoleQueryDepartmentMessage")
		public void toKnowledgeEditDataRoleQueryDepartmentMessage(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			Department department = publicService.findDepartment(id);
			LinkedHashMap<String, Object> userGroupList = new LinkedHashMap<String, Object>();
			userGroupList.put("id", department.getId());
			userGroupList.put("name", department.getName());
			userGroupList.put("description", department.getDescription());
			userGroupList.put("parentId", department.getParentId());
			
			if(department.getParentId() == 0){
				userGroupList.put("parentName", "根目录");
			}else{
				Department dt = publicService.findDepartment(department.getParentId());
				if(dt.getName().equals(department.getName())){
					userGroupList.put("parentName", "根目录");
				}else{
					userGroupList.put("parentName", dt.getName());
				}
			}
			
			String resultString = formatToJson(userGroupList);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		
		//删除部门
		@RequestMapping("knowledgeEditDataDeleteDepartment")
		public void toKnowledgeEditDataRoleDeleteDepartment(HttpServletRequest request,HttpServletResponse response) throws Exception {
			Integer id =Integer.parseInt(request.getParameter("id"));
			//导入
			int dataImports =0;
			List<DataImport> dataImport=publicService.getDataImport();
			for(DataImport dp:dataImport){
				if(dp.getCreateUserId() == id){
					dataImports = 1;
				}
			}
			//导出
			List<DataExport> dataExport=publicService.getDataExport();
			for(DataExport de:dataExport){
				if(de.getCreateUserId() == id){
					dataImports = 1;
				}
			}
			//知识发布
			List<DataSubmit> dataSubmit=publicService.getDataSubmit();
			for(DataSubmit ds:dataSubmit){
				if(ds.getCreateUserId() == id){
					dataImports = 1;
				}
			}
			//用户
			List<User> user =publicService.getUser();
			for(User u:user){
				if(u.getDepartmentId() == id){
					dataImports = 1;
				}
			}
			//知识加工
			List<Classes> classes =publicService.getClasses();
			Map<String,Object> conditions = new HashMap<String,Object>();
			conditions.put("=create_org_id", id);
			Boolean dataCount = true;
			for(Classes c:classes){
				long count =dynamicService.getDynamicCount(c.getNameEn(),conditions);
				if(0 != count){
					dataCount = false;
					break;
				}
			}
			if(dataImports ==0 && dataCount){
				Department department = publicService.findDepartment(id);
				int logTime=0;
				User u = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
				try {
					baseService.deleteDepartment(department);
				} catch (Exception e) {
					this.log(u.getId(), "general_data", null, null, "【"+u.getNickname()+"】【删除】部门【"+department.getName()+"】失败！请检查数据是否正确！", 1);
					logTime=1;
					e.printStackTrace();
				}
				if(logTime==0){
					this.log(u.getId(), "general_data", null, null, "【"+u.getNickname()+"】【删除】部门【"+department.getName()+"】成功！", 0);
				}
			
			}
			
			String resultString = formatToJson(dataImports);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		
		//修改部门
		@RequestMapping("knowledgeEditDataEditDepartment")
		public void toKnowledgeEditDataEditDepartment(HttpServletRequest request,HttpServletResponse response) throws Exception {
			
			String StringId=request.getParameter("id");
			String name =request.getParameter("name");
			String description =request.getParameter("description");
			int parentId =Integer.parseInt(request.getParameter("parentClassid"));
			Department dt = null;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));

			if(StringId.equals("")){
				Department department = new Department();
				department.setName(name);
				department.setParentId(parentId);
				department.setDescription(description);
				int logTime=0;
				try {
					dt=baseService.saveDepartment(department);
				} catch (Exception e) {
					this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】部门【"+name+"】失败！请检查数据是否正确！", 1);
					logTime=1;
					e.printStackTrace();
				}
				if(logTime==0){
					this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】部门【"+name+"】成功！", 0);
				}
			}else{
				int id =Integer.parseInt(StringId);
				Department department = publicService.findDepartment(id);
				department.setName(name);
				department.setParentId(parentId);
				department.setDescription(description);
				int logTime=0;
				try {
					dt=baseService.editDepartment(department);
				} catch (Exception e) {
					this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】部门【"+name+"】失败！请检查数据是否正确！", 1);
					logTime=1;
					e.printStackTrace();
				}
				if(logTime==0){
					this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】部门【"+name+"】成功！", 0);
				}
			}
			
			String resultString = formatToJson(dt);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		
		//查询部门信息
		@RequestMapping("knowledgeEditDataRoleQueryDepartmentUser")
		public void toKnowledgeEditDataRoleQueryDepartmentUser(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			List<User> user =publicService.getUser();
			
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			
				for(User users:user){
					if(users.getDepartmentId() == id){
						mp = new LinkedHashMap<String, Object>();
						mp.put("id", users.getId());
						mp.put("name", users.getUsername());
						r.add(mp);
					}
				}
			
			String resultString = formatToJson(r);
			super.pringWriterToPage(resultString, "application/json", response);
		}
		
		/**
		 * 菜单
		 * 
		 */
		
		//查询菜单
		@RequestMapping("knowledgeEditDataQueryMent")
		public void toKnowledgeEditDataQueryMent(HttpServletResponse response) throws Exception {
			
			List<Menu> menu = publicService.getMenu();
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			for (int i = 0; i < menu.size(); i++) {
				Menu m = menu.get(i);
					mp = new LinkedHashMap<String, Object>();
					mp.put("id", m.getId());
					mp.put("name", m.getName());
					mp.put("pId", m.getParentId());
					r.add(mp);
			}
			String result = formatToJson(r);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		//添加菜单
		@RequestMapping("knowledgeEditDataAddMent")
		public void toKnowledgeEditDataAddMent(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String name =request.getParameter("name");
			String description =request.getParameter("description");
			String url =request.getParameter("url");
			String headline =request.getParameter("headline");
			int sort =Integer.parseInt(request.getParameter("sort"));
			int status =Integer.parseInt(request.getParameter("stauts"));
			int parentId =Integer.parseInt(request.getParameter("parentid"));
			Menu menu = new Menu();
			menu.setName(name);
			menu.setDescription(description);
			menu.setUrl(url);
			menu.setLevel(1);
			menu.setSort(sort);
			menu.setIcon(headline);
			menu.setStatus(status);
			menu.setParentId(parentId);
			
			Menu m=null;
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			try {
				m = baseService.saveMenu(menu);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】菜单【"+name+"】失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】菜单【"+name+"】成功！", 0);
			}
			
			String result = formatToJson(m);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}

		//删除菜单
		@RequestMapping("knowledgeEditDataDeleteMent")
		public void toKnowledgeEditDataDeleteMent(HttpServletRequest request,HttpServletResponse response) throws Exception {
			
			int id =Integer.parseInt(request.getParameter("id"));
			Menu menu=publicService.findMenu(id);
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			try {
				baseService.deleteMenu(menu);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】菜单【"+menu.getName()+"】失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】菜单【"+menu.getName()+"】成功！", 0);
			}
			
			String result = formatToJson(1);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		//修改菜单
		@RequestMapping("knowledgeEditDataUploadMent")
		public void toKnowledgeEditDataUploadMent(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String name =request.getParameter("name");
			String description =request.getParameter("description");
			String url =request.getParameter("url");
			String headline =request.getParameter("headline");
			int sort =Integer.parseInt(request.getParameter("sort"));
			/*int level =Integer.parseInt(request.getParameter("level"))*/;
			int status =Integer.parseInt(request.getParameter("stauts"));
			int parentId =Integer.parseInt(request.getParameter("parentid"));
			int id =Integer.parseInt(request.getParameter("id"));
			Menu menu = publicService.findMenu(id); ;
			menu.setName(name);
			menu.setDescription(description);
			menu.setUrl(url);
			menu.setLevel(1);
			menu.setStatus(status);
			menu.setParentId(parentId);
			menu.setSort(sort);
			menu.setIcon(headline);
			
			Menu m=null;
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			try {
				m = baseService.editMenu(menu);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】菜单【"+menu.getName()+"】失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】菜单【"+menu.getName()+"】成功！", 0);
			}
			
			String result = formatToJson(m);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		//修改菜单查询方法
		@RequestMapping("knowledgeEditDataEditMent")
		public void toKnowledgeEditDataEditMent(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			Menu menu=publicService.findMenu(id);
			List<Menu> menuList = publicService.getMenu();
			LinkedHashMap<String, Object> menuMap = new LinkedHashMap<String, Object>();
			for(Menu m:menuList){
				if(menu.getParentId() == 0){
					menuMap.put("parentName", "根目录");
				}else if(menu.getParentId() == m.getId()){
						menuMap.put("parentName", m.getName());
					}
			}
			menuMap.put("level", menu.getLevel());
			menuMap.put("description", menu.getDescription());
			menuMap.put("name", menu.getName());
			menuMap.put("parentId", menu.getParentId());
			menuMap.put("status", menu.getStatus());
			menuMap.put("url", menu.getUrl());
			menuMap.put("sort", menu.getSort());
			menuMap.put("headline", menu.getIcon());
			String result = formatToJson(menuMap);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		/**
		 * 按钮
		 */
		//查询按钮
		@RequestMapping("knowledgeEditDataQueryMentButton")
		public void toKnowledgeEditDataQueryMentButton(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
			queryParams.put("=,menuId", id);
			List<MenuButton> menuButton = publicService.getMenuButton(queryParams);
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			for(MenuButton  mb: menuButton){
				if(mb.getMenuId() == id){
					mp = new LinkedHashMap<String, Object>();
					mp.put("id", mb.getId());
					mp.put("menuId", mb.getMenuId());
					mp.put("name", mb.getName());
					mp.put("status", mb.getStatus());
					mp.put("title", mb.getTitle());
					mp.put("code", mb.getCode());
					r.add(mp);
				}
			}
			String result = formatToJson(r);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		//复选选中按钮
		@RequestMapping("knowledgeEditDataPitchMentButton")
		public void toKnowledgeEditDataPitchMentButton(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
			queryParams.put("=,menuId", id);
			List<MenuButton> menuButton = publicService.getMenuButton(queryParams);
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			for(MenuButton  mb: menuButton){
				mp = new LinkedHashMap<String, Object>();
				if(mb.getMenuId() == id && mb.getStatus() == 0){
					mp.put("pitch", 1);
				}
					mp.put("id", mb.getId());
					mp.put("menuId", mb.getMenuId());
					mp.put("name", mb.getName());
					mp.put("status", mb.getStatus());
					mp.put("title", mb.getTitle());
					mp.put("code", mb.getCode());
					r.add(mp);
			}
			String result = formatToJson(r);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		//保存按钮
		@RequestMapping("knowledgeEditDataAddMentButton")
		public void toKnowledgeEditDataAddMentButton(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String name =request.getParameter("name");
			String title =request.getParameter("title");
			String code =request.getParameter("code");
			int menuId =Integer.parseInt(request.getParameter("menuld"));
			int status =Integer.parseInt(request.getParameter("status"));
			
			MenuButton menuButton = new MenuButton();
			menuButton.setCode(code);
			menuButton.setMenuId(menuId);
			menuButton.setName(name);
			menuButton.setStatus(status);
			menuButton.setTitle(title);
			
			MenuButton mb =null;
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			Menu menu=publicService.findMenu(menuId);
			try {
				mb = baseService.saveMenuButton(menuButton);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】菜单【"+menu.getName()+"】下【"+name+"】按钮失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【新增】菜单【"+menu.getName()+"】下【"+name+"】按钮成功！", 0);
			}
			
			String result = formatToJson(mb);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		//修改按钮
		@RequestMapping("knowledgeEditDataUploadMentButton")
		public void toKnowledgeEditDataUpoladMentButton(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String name =request.getParameter("name");
			String title =request.getParameter("title");
			String code =request.getParameter("code");
			int menuId =Integer.parseInt(request.getParameter("menuld"));
			int status =Integer.parseInt(request.getParameter("status"));
			int buttonid =Integer.parseInt(request.getParameter("buttonid"));
			
			MenuButton menuButton = publicService.findMenuButton(buttonid);
			menuButton.setCode(code);
			menuButton.setMenuId(menuId);
			menuButton.setName(name);
			menuButton.setStatus(status);
			menuButton.setTitle(title);
			
			MenuButton mb=null;
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			Menu menu=publicService.findMenu(menuId);
			try {
				mb = baseService.editMenuButton(menuButton);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】菜单【"+menu.getName()+"】下【"+name+"】按钮失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】菜单【"+menu.getName()+"】下【"+name+"】按钮成功！", 0);
			}
			
			String result = formatToJson(mb);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		//查询按钮详情
		@RequestMapping("knowledgeEditDataQueryButton")
		public void toKnowledgeEditDataQueryButton(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			MenuButton m =publicService.findMenuButton(id);
			String result = formatToJson(m);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		//删除按钮
		@RequestMapping("knowledgeEditDataDeleteMenuButton")
		public void toKnowledgeEditDatadeleteMenuButton(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			int menuId =Integer.parseInt(request.getParameter("menuId"));
			MenuButton menuButton =publicService.findMenuButton(id);
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			Menu menu=publicService.findMenu(menuId);
			try {
				baseService.deleteMenuButton(menuButton);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】菜单【"+menu.getName()+"】下【"+menuButton.getName()+"】按钮失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【删除】菜单【"+menu.getName()+"】下【"+menuButton.getName()+"】按钮成功！", 0);
			}
			
			String result = formatToJson(menuButton);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		/**
		 * 权限
		 */
		//角色列表
		@RequestMapping("knowledgeEditDataQueryJurisdiction")
		public void toKnowledgeEditDataQueryJurisdiction(HttpServletRequest request,HttpServletResponse response) throws Exception {
			List<Role> role= publicService.getRole();
			for(int i=0; i<role.size();i++){
				if(role.get(i).getId() == 1){
					role.remove(i);
				}
			}
			String result = formatToJson(role);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		//菜单列表
		@RequestMapping("knowledgeEditDataJurisdictionMenu")
		public void toKnowledgeEditDataJurisdictionMenu(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			List<Permission> permission=publicService.getPermission();
			String menuS ="";
			for(Permission p:permission){
				if(p.getRoleId() == id){
					menuS =p.getMenuIds();
				}
			}
			String[] sourceStrArray=null;
			if(!menuS.equals("")){
				sourceStrArray = menuS.split(",");
			}
				List<Menu> menu = publicService.getMenu();
				List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
				LinkedHashMap<String, Object> mp = null;
				for (int i = 0; i < menu.size(); i++) {
					Menu m = menu.get(i);
					mp = new LinkedHashMap<String, Object>();
					mp.put("id", m.getId());
					mp.put("name", m.getName());
					mp.put("pId", m.getParentId());
					if(sourceStrArray!=null){
						for (int j =0;j< sourceStrArray.length; j++){
							if(sourceStrArray[j]!=null && sourceStrArray[j]!=""){
								if(Integer.parseInt(sourceStrArray[j]) == m.getId()){
									mp.put("page", 0);
								}
							}
						}
					}
					r.add(mp);
				}
			String result = formatToJson(r);
			//System.out.println(result);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		// 插入  权限表
		@RequestMapping("menuEditSave")
		@ResponseBody
		public void menuEditSave(HttpServletRequest request,
				HttpServletResponse response) throws Exception {
			// System.out.println("dictAddandUpdate");
			String roleid = request.getParameter("roleid");
			String menuids = request.getParameter("menuids");
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			Permission permission = new Permission();
			permission.setRoleId((Integer.parseInt(roleid)));
			permission.setMenuIds(menuids);
			permission.setMenuIds(menuids);
			HashMap<String, Object> queryParams = new HashMap<String, Object>();
			queryParams.put("=,roleId",roleid);
			List<Permission> list=publicService.getPermission(queryParams);
			Permission permission2=null;
			for(Permission p :list){
				p.setMenuIds(menuids);
				int logTime=0;
				Role role=publicService.findRole(Integer.parseInt(roleid));
				try {
					baseService.editPermission(p);
				} catch (Exception e) {
					this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】角色【"+role.getName()+"】下菜单失败！请检查数据是否正确！", 1);
					logTime=1;
					e.printStackTrace();
				}
				if(logTime==0){
					this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】角色【"+role.getName()+"】下菜单成功！", 0);
				}
			
			}
			if(list.size()<1){
				int logTime=0;
				Role role=publicService.findRole(Integer.parseInt(roleid));
				try {
					permission2 =baseService.savePermission(permission);
				} catch (Exception e) {
					this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】角色【"+role.getName()+"】下菜单失败！请检查数据是否正确！", 1);
					logTime=1;
					e.printStackTrace();
				}
				if(logTime==0){
					this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】角色【"+role.getName()+"】下菜单成功！", 0);
				}
			}
			
			String result = formatToJson(permission2);
			// System.out.println("resultadd    Dict 插入  更新：" + result);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		//菜单按钮	
		@RequestMapping("knowledgeEditDataQueryJurisdictionMenu")
		public void toKnowledgeEditDataQueryJurisdictionMenu(HttpServletRequest request,HttpServletResponse response) throws Exception {

			int id =Integer.parseInt(request.getParameter("id"));
			HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
			queryParams.put("=,menuId", id);
			List<MenuButton> menuButton = publicService.getMenuButton(queryParams);
			
			List<PermissionButton> permissionButton =publicService.getPermissionButton();
			String menuButtonS="";
			for(PermissionButton pb : permissionButton){
				if(pb.getMenuId() == id){
					menuButtonS = pb.getMenuButtonIds();
				}
			}
			String[] menubutton=null;
			if(!menuButtonS.equals("")){
				menubutton =menuButtonS.split(":");
			}
			
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			for(MenuButton  mb: menuButton){
				mp = new LinkedHashMap<String, Object>();
					mp.put("id", mb.getId());
					if(menubutton !=null){
						for (int i = 0; i < menubutton.length; i++) {
							if(Integer.parseInt(menubutton[i]) == mb.getId()){
								mp.put("page", 1);
							}
						}
					}
					mp.put("menuId", mb.getMenuId());
					mp.put("name", mb.getName());
					mp.put("status", mb.getStatus());
					mp.put("title", mb.getTitle());
					mp.put("code", mb.getCode());
					r.add(mp);
			}
			String result = formatToJson(r);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		//保存按钮
		@RequestMapping("knowledgeEditDataAddJurisdictionButton")
		public void toKnowledgeEditDataAddJurisdictionButton(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			int roleid =Integer.parseInt(request.getParameter("roleid"));
			String[] button =request.getParameterValues("button");
			String menubutton = "";
			//选中
			if(button !=null ){
				for (int i = 0; i < button.length; i++) {
					menubutton += button[i]+":";
				}
			}
			
			
			List<PermissionButton> permissionButton =publicService.getPermissionButton();
			for(PermissionButton pb : permissionButton){
				if(pb.getMenuId() == id){
					baseService.deletePermissionButton(publicService.findPermissionButton(pb.getId()));
				}
			}
			
			PermissionButton pButton = new PermissionButton();
			pButton.setMenuId(id);
			pButton.setMenuButtonIds(menubutton);
			
			PermissionButton p=null;
			int logTime=0;
			User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			Role role=publicService.findRole(roleid);
			Menu menu=publicService.findMenu(id);
			try {
				p = baseService.savePermissionButton(pButton);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】角色【"+role.getName()+"】下【"+menu.getName()+"】菜单按钮失败！请检查数据是否正确！", 1);
				logTime=1;
				e.printStackTrace();
			}
			if(logTime==0){
				this.log(user.getId(), "general_data", null, null, "【"+user.getNickname()+"】【修改】角色【"+role.getName()+"】下【"+menu.getName()+"】菜单按钮成功！", 0);
			}
			
			String result = formatToJson(p);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		
		/**
		 * 知识分类权限
		 */
		//部门
		@RequestMapping("knowledgeEditDataQueryJurisdictionUser")
		public void toKnowledgeEditDataQueryJurisdictionUser(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int id =Integer.parseInt(request.getParameter("id"));
			List<User> user = publicService.getUser();
			List<PermissionClasses> domainPermission =publicService.getPermissionClasses();
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			String users ="";
			for(PermissionClasses dp:domainPermission){
				if(dp.getDepartmentId() == id){
					
				}
			}
			if(users.equals("")){
				for(User  u: user){
					if(u.getDepartmentId() == id){
						mp = new LinkedHashMap<String, Object>();
						mp.put("id", u.getId());
						mp.put("userName", u.getUsername());
						r.add(mp);
					}
				}
			}else{
				String[] sourceStrArray = users.split(":");
				for(User  u: user){
				if(u.getDepartmentId() == id){
					mp = new LinkedHashMap<String, Object>();
					for (int j =0;j< sourceStrArray.length; j++){
						if(Integer.parseInt(sourceStrArray[j]) == u.getId() ){
							mp.put("pitch", 1);
						}
					}
						mp.put("id", u.getId());
						mp.put("userName", u.getUsername());
						r.add(mp);
					}
				}
			}
			String result = formatToJson(r);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		//知识分类
		@RequestMapping("knowledgeEditDataQueryJurisdictionDomain")
		public void toKnowledgeEditDataQueryJurisdictionDomain(HttpServletRequest request,HttpServletResponse response) throws Exception {
			int repositoryId =Integer.parseInt(request.getParameter("repositoryId"));
			String[] classesId =request.getParameterValues("classesId");
			
			int returnInt=0;
			HashMap<String, Object> queryParams=new HashMap<String, Object>();
			queryParams.put("=,departmentId", repositoryId);
			List<PermissionClasses> permissionClasses=publicService.getPermissionClasses(queryParams);
			if(permissionClasses.size() !=0){
				for(PermissionClasses dc :permissionClasses){
						baseService.deletePermissionClasses(dc);
				}
			}
			if(classesId != null){
			for (int i = 0; i < classesId.length; i++) {
					PermissionClasses pClasses=new PermissionClasses();
					pClasses.setClassesId(Integer.parseInt(classesId[i]));
					pClasses.setDepartmentId(repositoryId);
					baseService.savePermissionClasses(pClasses);
				}
				returnInt=1;
			}
		
			String result = formatToJson(returnInt);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		
		//保存知识加工
		@RequestMapping("knowledgeEditDataAddJurisdictionDomain")
		public void toKnowledgeEditDataAddJurisdictionDomain(HttpServletRequest request,HttpServletResponse response) throws Exception {
			String repositoryId =request.getParameter("id");
			HashMap<String, Object> queryParams=new HashMap<String, Object>();
			if(repositoryId != null && !"".equals(repositoryId)){
				queryParams.put("=,department_id", repositoryId);
			}
			
			List<PermissionClasses> permissionClasses=publicService.getPermissionClasses(queryParams);
			List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			for(PermissionClasses pc : permissionClasses){
				Classes classes=publicService.findClasses(pc.getClassesId());
				mp=new LinkedHashMap<String, Object>();
				mp.put("nameZh", classes.getNameZh());
				mp.put("id", classes.getId());
				r.add(mp);
			}
			String result = formatToJson(r);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
		//查询知识库
		@RequestMapping("knowledgeEditDataQuerydomain")
		public void toKnowledgeEditDataQueryDomain(HttpServletRequest request,HttpServletResponse response) throws Exception {
			LinkedHashMap<String, Object> mp = null;
			List<LinkedHashMap<String, Object>> rightContent = new ArrayList<LinkedHashMap<String, Object>>();
			List<Classes> classesAll = publicService.getClasses();
				for( Classes classes :classesAll){
					mp =new LinkedHashMap<String, Object>();
					mp.put("nameZh", classes.getNameZh());
					mp.put("nameEn", classes.getNameEn());
					mp.put("classesId", classes.getId());
					mp.put("description", classes.getDescription());
					rightContent.add(mp);
				}
			String result = formatToJson(rightContent);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
	//导出范畴
	@RequestMapping("knowledgeEditDataCategory")
	public void category(HttpServletRequest request,HttpServletResponse response){
		DocumentBuilderFactory  fct=DocumentBuilderFactory.newInstance();
		 DocumentBuilder bui;
		try {
			//驱动
		bui = fct.newDocumentBuilder();
		//创建对象
        Document doc=bui.newDocument();
       //设置根目录 
       Element thesauri_word_data=doc.createElement("thesauri_word_data");
       
       List<ThesauriWordCategory> thesauriWordCategory =iWordService.getThesauriWordCategory();
		for(ThesauriWordCategory twc:thesauriWordCategory){
			//设置二级目录
			Element thesauri_word_category=doc.createElement("thesauri_word_category");
			
			//二级标题属性
			Attr data_id = doc.createAttribute("id");
			//赋值
			data_id.setNodeValue(twc.getId().toString());
			//写入二级目录
			thesauri_word_category.setAttributeNode(data_id);
			
			
			//创建节点
			Element category_name = doc.createElement("category_name");
			//赋值
			category_name.setTextContent(twc.getCategoryName());
			
			Element category_sid = doc.createElement("category_sid");
			category_sid.setTextContent(twc.getCategorySid());
			
			
			Element parent_id=doc.createElement("parent_id");
			parent_id.setTextContent(twc.getParentId());
			
			//将节点写入二级目录
			thesauri_word_category.appendChild(category_name);
			thesauri_word_category.appendChild(category_sid);
			thesauri_word_category.appendChild(parent_id);
			
			//创建三级目录
			Element thesauri_word_list=doc.createElement("thesauri_word_list");
			HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
			queryParams.put("=,thesauriWordCategoryIds", twc.getCategorySid());
			int thesauriWordCount =iWordService.getThesauriWordCount(queryParams).intValue();
			List<ThesauriWord> thesauriWord=iWordService.getThesauriWord(queryParams, 1, thesauriWordCount);
			if(thesauriWordCount != 0 ){
				for(ThesauriWord tw :thesauriWord){
					
				//创建四级目录
				Element thesauri_word=doc.createElement("thesauri_word");
				
				//属性
				Attr id1=doc.createAttribute("id");
				id1.setNodeValue(tw.getId().toString());
				thesauri_word.setAttributeNode(id1);
				
				//节点
				Element word_name=doc.createElement("word_name");
				word_name.setTextContent(tw.getWordName());
				
				
				Element is_top_term=doc.createElement("is_top_term");
				is_top_term.setTextContent(tw.getIsTopTerm());
				
				
				Element word_pinyin=doc.createElement("word_pinyin");
				word_pinyin.setTextContent(tw.getWordPinyin());
				
				
				Element word_english=doc.createElement("word_english");
				word_english.setTextContent(tw.getWordEnglish());
				if(tw.getScopeNote()!=null){
					Element scope_note=doc.createElement("scope_note");
					scope_note.setTextContent(tw.getScopeNote());
					thesauri_word.appendChild(scope_note);
				}
				
				if(tw.getScopeNote()!=null){
					Element usage_note=doc.createElement("usage_note");
					usage_note.setTextContent(tw.getUsageNote());
					thesauri_word.appendChild(usage_note);
				}
				
				if( tw.getScopeNote()!=null){
					Element historical_note=doc.createElement("historical_note");
					historical_note.setTextContent(tw.getHistoricalNote());
					thesauri_word.appendChild(historical_note);
				}
				
				//赋值
				thesauri_word.appendChild(word_name);
				thesauri_word.appendChild(is_top_term);
				thesauri_word.appendChild(word_pinyin);
				thesauri_word.appendChild(word_english);
				
				//写入上级目录
				thesauri_word_list.appendChild(thesauri_word);
			
				}
				//写入上级目录
				thesauri_word_category.appendChild(thesauri_word_list);
			}
			//写入上级目录
			thesauri_word_data.appendChild(thesauri_word_category);
		}
		//目录保存到doc
       doc.appendChild(thesauri_word_data);
       
       //step9:获得一个TransformerFactory对象  
       TransformerFactory transformerFactory = TransformerFactory.newInstance();  
       //step10:获得一个Transformer对象  
       Transformer transformer = transformerFactory.newTransformer();  
       //step11:把document对象用一个DOMSource对象包装起来  
       Source xmlSource = new DOMSource(doc);  
       //step12:建立一个存储目标对象  
       //获取服务器地址
       ServletContext sc = request.getSession().getServletContext();
       String dir =sc.getRealPath("/XMLFile/");
       File dirFile = new File(dir);
       if (!dirFile.exists()) {
			dirFile.mkdirs();
		}
       
       String random = System.nanoTime()+".xml";
       File downFile = new File(dirFile, random);
       Result outputTarget = new StreamResult(downFile);  
       //step13:生成相应的xml文件  
       transformer.setOutputProperty(OutputKeys.INDENT, "yes");  
       transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); 
       transformer.transform(xmlSource, outputTarget);
       
       // 下载文件
       FileDownloadUtil.download(downFile, "范畴.xml", request, response);
            
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
	}
	//导出数据
	@RequestMapping("knowledgeEditDataVocabulary")
	public void vocabulary(HttpServletRequest request,HttpServletResponse response){
		
		 DocumentBuilderFactory  fct=DocumentBuilderFactory.newInstance();
		 DocumentBuilder bui;
		try {
			//驱动
		bui = fct.newDocumentBuilder();
		//创建对象
         Document doc=bui.newDocument();
        //设置根目录 
        Element thesauri_word_data=doc.createElement("thesauri_word_data");
        
        int thesauriWordCount =iWordService.getThesauriWordCount(null).intValue();
		List<ThesauriWord> thesauriWord=iWordService.getThesauriWord(null, 1, thesauriWordCount);
		
		for(ThesauriWord tw:thesauriWord){
			//设置二级目录
			Element thesauri_word=doc.createElement("thesauri_word");
			
			//二级标题属性
			Attr id = doc.createAttribute("id");
			//赋值
			id.setNodeValue(tw.getId().toString());
			//写入二级目录
			thesauri_word.setAttributeNode(id);
			
			
			//创建节点
			Element word_name = doc.createElement("word_name");
			//赋值
			word_name.setTextContent(tw.getWordName());
			
			Element is_top_term = doc.createElement("is_top_term");
			is_top_term.setTextContent(tw.getIsTopTerm());
			
			
			Element word_pinyin=doc.createElement("word_pinyin");
			word_pinyin.setTextContent(tw.getWordPinyin());
			
			Element word_english=doc.createElement("word_english");
			word_english.setTextContent(tw.getWordEnglish());
			
			if(tw.getScopeNote() != null){
				Element scope_note=doc.createElement("scope_note");
				scope_note.setTextContent(tw.getScopeNote());
				thesauri_word.appendChild(scope_note);
			}
			
			if(tw.getUsageNote() != null){
				Element usage_note=doc.createElement("usage_note");
				usage_note.setTextContent(tw.getUsageNote());
				thesauri_word.appendChild(usage_note);
			}
			
			if(tw.getHistoricalNote() != null){
				Element historical_note=doc.createElement("historical_note");
				historical_note.setTextContent(tw.getHistoricalNote());
				thesauri_word.appendChild(historical_note);
			}
			
			//将节点写入二级目录
			thesauri_word.appendChild(word_name);
			thesauri_word.appendChild(is_top_term);
			thesauri_word.appendChild(word_pinyin);
			thesauri_word.appendChild(word_english);
			
			String thesauriWordCategoryId="";
			String thesauriWordCategoryName="";
			String thesauriWordCategorySid="";
			//创建三级目录
			Element thesauri_word_category=doc.createElement("thesauri_word_category");
			if(tw.getThesauriWordCategoryIds() !=null){
				String [] thesauriWordCategoryIds = tw.getThesauriWordCategoryIds().split(";");
				for (int i = 0; i < thesauriWordCategoryIds.length; i++) {
					HashMap<String, Object> queryParams2 = new LinkedHashMap<String, Object>();
					queryParams2.put("=,categorySid", thesauriWordCategoryIds[i]);
					List<ThesauriWordCategory> thesauriWordCategorys =iWordService.getThesauriWordCategory(queryParams2, 1, iWordService.getThesauriWordCategoryCount(queryParams2).intValue());
					for (int j = 0; j < thesauriWordCategorys.size(); j++) {
						ThesauriWordCategory thesauriWordCategory =thesauriWordCategorys.get(j);
						thesauriWordCategoryId += thesauriWordCategory.getId()+";";
						thesauriWordCategoryName += thesauriWordCategory.getCategoryName()+";";
						thesauriWordCategorySid += thesauriWordCategory.getCategorySid()+";";
					}
				}
			}
			
			if(!thesauriWordCategoryId.equals("")){
			//二级标题属性
			Attr data_id = doc.createAttribute("id");
			//赋值
			data_id.setNodeValue(thesauriWordCategoryId);
			//写入
			thesauri_word_category.setAttributeNode(data_id);
			}
			if(!thesauriWordCategoryName.equals("")){
		    //节点
			Element category_name=doc.createElement("category_name");
			category_name.setTextContent(thesauriWordCategoryName);
			thesauri_word_category.appendChild(category_name);
			
			Element category_sid=doc.createElement("category_sid");
			category_sid.setTextContent(thesauriWordCategorySid);
			thesauri_word_category.appendChild(category_sid);
			//写入上级节点
			thesauri_word.appendChild(thesauri_word_category);
			}
			//创建四级目录
			Element thesauri_word_reference=doc.createElement("thesauri_word_reference");
			HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
			queryParams.put("=,thesauriWordId", tw.getId().toString());
			List<ThesauriWordReference> thesauriWordReference= iWordService.getThesauriWordReference(queryParams, 1, iWordService.getThesauriWordReferenceCount(queryParams).intValue());
			for (int i = 0; i < thesauriWordReference.size(); i++) {
				ThesauriWordReference map=thesauriWordReference.get(i);
					Element referenceRelationLabel=doc.createElement(map.getReferenceRelationLabel());
					referenceRelationLabel.setTextContent(iWordService.findThesauriWord(Integer.parseInt(map.getReferenceWordId())).getWordName());
					thesauri_word_reference.appendChild(referenceRelationLabel);
				

				
			
			}
				
		
			//写入上级目录
			thesauri_word.appendChild(thesauri_word_reference);
			//写入上级目录
			thesauri_word_data.appendChild(thesauri_word);
		}
		//目录保存到doc
        doc.appendChild(thesauri_word_data);
        
        //step9:获得一个TransformerFactory对象  
        TransformerFactory transformerFactory = TransformerFactory.newInstance();  
        //step10:获得一个Transformer对象  
        Transformer transformer = transformerFactory.newTransformer();  
        //step11:把document对象用一个DOMSource对象包装起来  
        Source xmlSource = new DOMSource(doc);  
        //step12:建立一个存储目标对象  
        //获取服务器地址
        ServletContext sc = request.getSession().getServletContext();
        String dir =sc.getRealPath("/XMLFile/");
        File dirFile = new File(dir);
        if (!dirFile.exists()) {
 			dirFile.mkdirs();
 		}
        
        String random = System.nanoTime()+".xml";
        File downFile = new File(dirFile, random);
        Result outputTarget = new StreamResult(downFile);  
        //step13:生成相应的xml文件  
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");  
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); 
        transformer.transform(xmlSource, outputTarget);
        
        // 下载文件
        FileDownloadUtil.download(downFile, "词表.xml", request, response);
        
		} catch (Exception e1) {
			e1.printStackTrace();
		} 
		
	}
	//导入叙词表
	@RequestMapping("importWord")
	public void importWord(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String urlFile = request.getParameter("urlFile");
		//访问前缀	
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		//磁盘前缀
		String adjunctPath =  XxlConfClient.get("dal.file.path", "");
		LinkedHashMap<String, Object> r = new LinkedHashMap<String, Object>();
		
		urlFile = urlFile.replaceAll(uploadPath, "");
		String lastType = urlFile.substring(urlFile.lastIndexOf(".")+1, urlFile.length());
		try {
			if("xml".equals(lastType)){
				String rXml = this.importWordXml(adjunctPath+"/"+urlFile);
				r.put("data", rXml);
			}else if("xls".equals(lastType) || "xlsx".equals(lastType)){
				String rExcel = this.importWordExcel(adjunctPath+"/"+urlFile);
				r.put("data", rExcel);
			}else{
				r.put("data", "type");
			}
		} catch (Exception e) {
			r.put("data", "no");
		}
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	//字典导入Excel
		public String importWordExcel(String path) throws Exception{
			String r = "yes";
			ThesauriWordModule atwm = null;
			try {
				List<Map<String, Object>> listThesauriWordModule = ExcelMore.readExcel(path,"listThesauriWordModule");
				for (Map<String, Object> m:listThesauriWordModule) {
					ThesauriWordModule twm = new ThesauriWordModule();
					twm.setNameZh(m.get("name_zh").toString());
					twm.setNameEn(m.get("name_en").toString());
					twm.setDescription(m.get("description").toString());
					twm.setSort(Integer.parseInt(m.get("sort").toString()));
					atwm = iWordService.saveThesauriWordModule(twm);
				}
				List<Map<String, Object>> listThesauriWordRelation = ExcelMore.readExcel(path,"listThesauriWordRelation");
				for (Map<String, Object> m:listThesauriWordRelation) {
					ThesauriWordRelation twr = new ThesauriWordRelation();
					twr.setNameEn(m.get("name_en").toString());
					twr.setNameZh(m.get("name_zh").toString());
					twr.setSort(Integer.parseInt(m.get("sort").toString()));
					twr.setDescription(m.get("description").toString());
					twr.setThesauriWordModuleId(atwm.getId());
					iWordService.saveThesauriWordRelation(twr);
				}
				List<Map<String, Object>> listThesauriWordCategory = ExcelMore.readExcel(path,"listThesauriWordCategory");
				HashMap<String, Object> queryParams = null;
				for (Map<String, Object> m:listThesauriWordCategory) {
					ThesauriWordCategory twc = new ThesauriWordCategory();
					twc.setCategoryName(m.get("category_name").toString());
					twc.setCategorySid(m.get("category_sid").toString());
					twc.setThesauriWordModuleId(atwm.getId());
					queryParams = new HashMap<String, Object>();
					queryParams.put("=,thesauri_word_module_id", atwm.getId());
					queryParams.put("=,category_name", m.get("category_pname"));
					List<ThesauriWordCategory> thesauriWordCategoryList = iWordService.getThesauriWordCategory(queryParams, 1, 1);
					if(null != thesauriWordCategoryList && thesauriWordCategoryList.size()>0 ){
						twc.setParentId(thesauriWordCategoryList.get(0).getId().toString());
					}
					iWordService.saveThesauriWordCategory(twc);
				}
				List<Map<String, Object>> listThesauriWord = ExcelMore.readExcel(path,"listThesauriWord");
				for (Map<String, Object> m:listThesauriWord) {
					ThesauriWord tw = new ThesauriWord();
					tw.setWordName(m.get("word_name").toString());
					tw.setIsTopTerm(m.get("is_top_term").toString());
					tw.setWordEnglish(m.get("word_english").toString());
					tw.setThesauriWordCategoryIds(m.get("thesauri_word_category_ids").toString());
					tw.setWordPinyin(m.get("word_pinyin").toString());
					tw.setScopeNote(m.get("scope_note").toString());
					tw.setUsageNote(m.get("usage_note").toString());
					tw.setHistoricalNote(m.get("historical_note").toString());
					tw.setWordFormal(Integer.parseInt(m.get("word_formal").toString()));
					tw.setThesauriWordModuleId(atwm.getId());
					if(null != m.get("word_pname") && !"".equals(m.get("word_pname"))){
						queryParams = new HashMap<String, Object>();
						queryParams.put("=,thesauri_word_module_id", atwm.getId());
						queryParams.put("=,word_name", m.get("word_pname"));
						List<ThesauriWord> thesauriWordList = iWordService.getThesauriWord(queryParams, 1, 1);
						if(null != thesauriWordList && thesauriWordList.size()>0 ){
							tw.setWordPid(thesauriWordList.get(0).getId());
						}
					}
					iWordService.saveThesauriWord(tw);
				}
				List<Map<String, Object>> listThesauriWordReference = ExcelMore.readExcel(path,"listThesauriWordReference");
				for (Map<String, Object> m:listThesauriWordReference) {
					ThesauriWordReference twre = new ThesauriWordReference();
					twre.setReferenceRelationLabel(m.get("reference_relation_label").toString());
					twre.setThesauriWordModuleId(atwm.getId());
					if(null != m.get("thesauri_word_name") && !"".equals(m.get("thesauri_word_name"))){
						queryParams = new HashMap<String, Object>();
						queryParams.put("=,thesauri_word_module_id", atwm.getId());
						queryParams.put("=,word_name", m.get("thesauri_word_name"));
						List<ThesauriWord> thesauriWordList = iWordService.getThesauriWord(queryParams, 1, 1);
						if(null != thesauriWordList && thesauriWordList.size()>0 ){
							twre.setThesauriWordId(thesauriWordList.get(0).getId().toString());
						}
					}
					if(null != m.get("reference_word_name") && !"".equals(m.get("reference_word_name"))){
						queryParams = new HashMap<String, Object>();
						queryParams.put("=,thesauri_word_module_id", atwm.getId());
						queryParams.put("=,word_name", m.get("reference_word_name"));
						List<ThesauriWord> thesauriWordList = iWordService.getThesauriWord(queryParams, 1, 1);
						if(null != thesauriWordList && thesauriWordList.size()>0 ){
							twre.setReferenceWordId(thesauriWordList.get(0).getId().toString());
						}
					}
					iWordService.saveThesauriWordReference(twre);
				}
			} catch (Exception e) {
				r = "no";
			}
			return r;
		}
		public String importWordXml(String path) throws Exception{
			String r = "yes";
			// 解析文件，生成document对象
			ThesauriWordModule atwm = null;
			try {
				DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
				Document document = builder.parse(new File(path));
				// 生成XPath对象
				XPath xpath = XPathFactory.newInstance().newXPath();
				// 获取节点集合
				NodeList listThesauriWordModule = (NodeList) xpath.evaluate("//thesauri_word_module",document, XPathConstants.NODESET);
				for (int i = 0; i < listThesauriWordModule.getLength(); i++) {
					Node m = listThesauriWordModule.item(i);

					String moduleNameZh = xpath.evaluate("name_zh", m,XPathConstants.STRING).toString();
					String moduleNameEn = xpath.evaluate("name_en", m,XPathConstants.STRING).toString();
					String moduleDescription = xpath.evaluate("description", m,XPathConstants.STRING).toString();
					String moduleSort = xpath.evaluate("sort", m,XPathConstants.STRING).toString();
					ThesauriWordModule twm = new ThesauriWordModule();
					twm.setNameZh(moduleNameZh);
					twm.setNameEn(moduleNameEn);
					twm.setDescription(moduleDescription);
					twm.setSort(Integer.parseInt(moduleSort));
					atwm = iWordService.saveThesauriWordModule(twm);
				}
				NodeList listThesauriWordRelation = (NodeList) xpath.evaluate("//thesauri_word_relation",document, XPathConstants.NODESET);
				for (int i = 0; i < listThesauriWordRelation.getLength(); i++) {
					Node m = listThesauriWordRelation.item(i);
					
					String relationNameZh = xpath.evaluate("name_zh", m,XPathConstants.STRING).toString();
					String relationNameEn = xpath.evaluate("name_en", m,XPathConstants.STRING).toString();
					String relationSort = xpath.evaluate("sort", m,XPathConstants.STRING).toString();
					String relationDescription = xpath.evaluate("description", m,XPathConstants.STRING).toString();
					ThesauriWordRelation twr = new ThesauriWordRelation();
					twr.setNameZh(relationNameZh);
					twr.setNameEn(relationNameEn);
					twr.setDescription(relationDescription);
					twr.setSort(Integer.parseInt(relationSort));
					twr.setThesauriWordModuleId(atwm.getId());
					iWordService.saveThesauriWordRelation(twr);
				}
				NodeList listThesauriWordCategory = (NodeList) xpath.evaluate("//thesauri_word_category",document, XPathConstants.NODESET);
				HashMap<String, Object> queryParams = null;

				for (int i = 0; i < listThesauriWordCategory.getLength(); i++) {
					Node m = listThesauriWordCategory.item(i);
					
					String categoryName = xpath.evaluate("category_name", m,XPathConstants.STRING).toString();
					String categorySid = xpath.evaluate("category_sid", m,XPathConstants.STRING).toString();
					String categoryPname = xpath.evaluate("category_pname", m,XPathConstants.STRING).toString();
					ThesauriWordCategory twc = new ThesauriWordCategory();
					twc.setCategoryName(categoryName);
					twc.setCategorySid(categorySid);
					twc.setThesauriWordModuleId(atwm.getId());
						queryParams = new HashMap<String, Object>();
						queryParams.put("=,thesauri_word_module_id", atwm.getId());
						queryParams.put("=,category_name", categoryPname);
						List<ThesauriWordCategory> thesauriWordCategoryList = iWordService.getThesauriWordCategory(queryParams, 1, 1);
						if(null != thesauriWordCategoryList && thesauriWordCategoryList.size()>0 ){
							twc.setParentId(thesauriWordCategoryList.get(0).getId().toString());
						}
					iWordService.saveThesauriWordCategory(twc);
				}
				
				NodeList listThesauriWord = (NodeList) xpath.evaluate("//thesauri_word",document, XPathConstants.NODESET);
				
				for (int i = 0; i < listThesauriWord.getLength(); i++) {
					Node m = listThesauriWord.item(i);
					
					String wordName = xpath.evaluate("word_name", m,XPathConstants.STRING).toString();
					String isTopTerm = xpath.evaluate("is_top_term", m,XPathConstants.STRING).toString();
					String wordEnglish = xpath.evaluate("word_english", m,XPathConstants.STRING).toString();
					String categoryIds = xpath.evaluate("thesauri_word_category_ids", m,XPathConstants.STRING).toString();
					String wordPinyin = xpath.evaluate("word_pinyin", m,XPathConstants.STRING).toString();
					String scopeNote = xpath.evaluate("scope_note", m,XPathConstants.STRING).toString();
					String usageNote = xpath.evaluate("usage_note", m,XPathConstants.STRING).toString();
					String historicalNote = xpath.evaluate("historical_note", m,XPathConstants.STRING).toString();
					String wordFormal = xpath.evaluate("word_formal", m,XPathConstants.STRING).toString();
					String wordPname = xpath.evaluate("word_pname", m,XPathConstants.STRING).toString();
					ThesauriWord tw = new ThesauriWord();
					tw.setWordName(wordName);
					tw.setIsTopTerm(isTopTerm);
					tw.setWordEnglish(wordEnglish);
					tw.setThesauriWordCategoryIds(categoryIds);
					tw.setWordPinyin(wordPinyin);
					tw.setScopeNote(scopeNote);
					tw.setUsageNote(usageNote);
					tw.setHistoricalNote(historicalNote);
					tw.setWordFormal(Integer.parseInt(wordFormal));
					tw.setThesauriWordModuleId(atwm.getId());
					if(null != wordPname && !"".equals(wordPname)){
						queryParams = new HashMap<String, Object>();
						queryParams.put("=,thesauri_word_module_id", atwm.getId());
						queryParams.put("=,word_name", wordPname);
						List<ThesauriWord> thesauriWordList = iWordService.getThesauriWord(queryParams, 1, 1);
						if(null != thesauriWordList && thesauriWordList.size()>0 ){
							tw.setWordPid(thesauriWordList.get(0).getId());
						}
					}
					iWordService.saveThesauriWord(tw);
				}
				NodeList listThesauriWordReference = (NodeList) xpath.evaluate("//thesauri_word_reference",document, XPathConstants.NODESET);
				
				for (int i = 0; i < listThesauriWordReference.getLength(); i++) {
					Node m = listThesauriWordReference.item(i);
					
					String relationLable = xpath.evaluate("reference_relation_label", m,XPathConstants.STRING).toString();
					String referenceTwname = xpath.evaluate("thesauri_word_name", m,XPathConstants.STRING).toString();
					String referenceRwname = xpath.evaluate("reference_word_name", m,XPathConstants.STRING).toString();
					ThesauriWordReference twre = new ThesauriWordReference();
					twre.setReferenceRelationLabel(relationLable);
					twre.setThesauriWordModuleId(atwm.getId());
					if(null != referenceTwname && !"".equals(referenceTwname)){
						queryParams = new HashMap<String, Object>();
						queryParams.put("=,thesauri_word_module_id", atwm.getId());
						queryParams.put("=,word_name", referenceTwname);
						List<ThesauriWord> thesauriWordList = iWordService.getThesauriWord(queryParams, 1, 1);
						if(null != thesauriWordList && thesauriWordList.size()>0 ){
							twre.setThesauriWordId(thesauriWordList.get(0).getId().toString());
						}
					}
					if(null != referenceRwname && !"".equals(referenceRwname)){
						queryParams = new HashMap<String, Object>();
						queryParams.put("=,thesauri_word_module_id", atwm.getId());
						queryParams.put("=,word_name", referenceRwname);
						List<ThesauriWord> thesauriWordList = iWordService.getThesauriWord(queryParams, 1, 1);
						if(null != thesauriWordList && thesauriWordList.size()>0 ){
							twre.setReferenceWordId(thesauriWordList.get(0).getId().toString());
						}
					}
					iWordService.saveThesauriWordReference(twre);
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return r;
		}
	// 叙词表导出Excel
	@RequestMapping("exportExcelWord")
	public void exportExcelWord(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");
		String wordClasses = request.getParameter("wordClasses");
		String path =  XxlConfClient.get("dal.file.path", "") +"/";
		ThesauriWordModule thesauriWordModule=iWordService.findThesauriWordModule(Integer.parseInt(wordClasses));
		HashMap<String, Object> twmParam = new HashMap<String, Object>();
		twmParam.put("=,thesauri_word_module_id", thesauriWordModule.getId());
		 //thesauri_word_module
		List<HashMap<String, Object>> listThesauriWordModule = new ArrayList<HashMap<String, Object>>();
		HashMap<String, Object> twmMap = new LinkedHashMap<String, Object>();
		twmMap.put("id", thesauriWordModule.getId());
		twmMap.put("name_zh", thesauriWordModule.getNameZh());
		twmMap.put("name_en", thesauriWordModule.getNameEn());
		twmMap.put("description", thesauriWordModule.getDescription());
		twmMap.put("sort", thesauriWordModule.getSort());
		listThesauriWordModule.add(twmMap);
		//thesauri_word_relation
		List<ThesauriWordRelation> thesauriWordRelation=iWordService.getThesauriWordRelation(twmParam,1,iWordService.getThesauriWordRelationCount(twmParam));
		List<HashMap<String, Object>> listThesauriWordRelation = new ArrayList<HashMap<String, Object>>();
		HashMap<String, Object> twrMap = null;
        for(ThesauriWordRelation twr:thesauriWordRelation){
        	twrMap = new LinkedHashMap<String, Object>();
        	twrMap.put("id", twr.getId().toString());
        	twrMap.put("name_zh", twr.getNameZh());
        	twrMap.put("name_en", twr.getNameEn());
        	twrMap.put("sort", twr.getSort().toString());
        	twrMap.put("description", twr.getDescription()!=null?twr.getDescription():"");
        	twrMap.put("thesauri_word_module_id", twr.getThesauriWordModuleId().toString());
        	listThesauriWordRelation.add(twrMap);
        }
        //thesauri_word_category
        List<ThesauriWordCategory> thesauriWordCategory=iWordService.getThesauriWordCategory(twmParam,1,iWordService.getThesauriWordCategoryCount(twmParam));
		List<HashMap<String, Object>> listThesauriWordCategory = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> twcMap = null;
        for(ThesauriWordCategory twc:thesauriWordCategory){
        	twcMap = new LinkedHashMap<String, Object>();
        	twcMap.put("id", twc.getId().toString());
        	twcMap.put("category_name", twc.getCategoryName());
        	twcMap.put("category_sid", twc.getCategorySid());
        	ThesauriWordCategory twcname = iWordService.findThesauriWordCategory(Integer.parseInt(twc.getParentId()));
        	twcMap.put("category_pname", twcname!=null?twcname.getCategoryName():"");
        	twcMap.put("thesauri_word_module_id", twc.getThesauriWordModuleId().toString());
        	listThesauriWordCategory.add(twcMap);
        }
       //thesauri_word_reference
        List<ThesauriWordReference> thesauriWordReference=iWordService.getThesauriWordReference(twmParam,1,iWordService.getThesauriWordReferenceCount(twmParam));	
		List<HashMap<String, Object>> listThesauriWordReference = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> twreMap = null;
        for(ThesauriWordReference twre:thesauriWordReference){
        	twreMap = new LinkedHashMap<String, Object>();
        	twreMap.put("id", twre.getId().toString());
        	ThesauriWord twname = iWordService.findThesauriWord(Integer.parseInt(twre.getThesauriWordId()));
        	ThesauriWord rwname = iWordService.findThesauriWord(Integer.parseInt(twre.getReferenceWordId()));
        	twreMap.put("thesauri_word_name", twname!=null?twname.getWordName():"");
        	twreMap.put("reference_word_name", rwname!=null?rwname.getWordName():"");
        	twreMap.put("reference_relation_label", twre.getReferenceRelationLabel());
        	twreMap.put("thesauri_word_module_id", twre.getThesauriWordModuleId().toString());
        	listThesauriWordReference.add(twreMap);
        }        
        //thesauri_word
        List<ThesauriWord> thesauriWord=iWordService.getThesauriWord(twmParam,1,iWordService.getThesauriWordCount(twmParam));
		List<HashMap<String, Object>> listThesauriWord = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> twMap = null;
        for(ThesauriWord tw:thesauriWord){
        	twMap = new LinkedHashMap<String, Object>();
        	twMap.put("id", tw.getId().toString());
        	twMap.put("word_name", tw.getWordName()!=null?tw.getWordName():"");
        	twMap.put("is_top_term", tw.getIsTopTerm()!=null?tw.getIsTopTerm():"");
        	twMap.put("word_english", tw.getWordEnglish()!=null?tw.getWordEnglish():"");
        	twMap.put("thesauri_word_category_ids", tw.getThesauriWordCategoryIds()!=null?tw.getThesauriWordCategoryIds():"");
        	twMap.put("word_pinyin", tw.getWordPinyin()!=null?tw.getWordPinyin():"");
        	twMap.put("scope_note", tw.getScopeNote()!=null?tw.getScopeNote():"");
        	twMap.put("usage_note", tw.getUsageNote()!=null?tw.getUsageNote():"");
        	twMap.put("historical_note", tw.getHistoricalNote()!=null?tw.getHistoricalNote():"");       	
        	if(tw.getWordPid()!=null&&!tw.getWordPid().toString().equals("")){
        		twMap.put("word_pname", iWordService.findThesauriWord(tw.getWordPid()).getWordName());
        	}else{
        		twMap.put("word_pname", "");
        	}
        	twMap.put("word_formal", tw.getWordFormal()!=null?tw.getWordFormal():"");
        	twMap.put("thesauri_word_module_id", tw.getThesauriWordModuleId().toString());
        	listThesauriWord.add(twMap);
        }   
        
		HashMap<String, List<HashMap<String, Object>>> excelMap = new LinkedHashMap<String, List<HashMap<String, Object>>>();
		excelMap.put("listThesauriWordModule", listThesauriWordModule);
		excelMap.put("listThesauriWordRelation", listThesauriWordRelation);
		excelMap.put("listThesauriWordCategory", listThesauriWordCategory);
		excelMap.put("listThesauriWordReference", listThesauriWordReference);
		excelMap.put("listThesauriWord", listThesauriWord);
		ExcelMore.writeExcelListMore(path + thesauriWordModule.getNameEn() + ".xlsx", excelMap, 1);
		downloadkk(request, response, thesauriWordModule.getNameEn() + ".xlsx", path);
	}
	//叙词表导出XML
	@RequestMapping("exportXmlWord")
	public void exportXmlWord(HttpServletRequest request,HttpServletResponse response){
		String wordClasses = request.getParameter("wordClasses");
		DocumentBuilderFactory  fct=DocumentBuilderFactory.newInstance();
		DocumentBuilder bui;
		try {
			//驱动
			bui = fct.newDocumentBuilder();
			//创建对象
			Document doc=bui.newDocument();
			//设置根目录 
			Element thesauri_word_data=doc.createElement("thesauri_word_data");
			doc.appendChild(thesauri_word_data);
			ThesauriWordModule thesauriWordModule=iWordService.findThesauriWordModule(Integer.parseInt(wordClasses));
			HashMap<String, Object> twmParam = new HashMap<String, Object>();
			twmParam.put("=,thesauri_word_module_id", thesauriWordModule.getId());
            //thesauri_word_module
			Element thesauri_word_module=doc.createElement("thesauri_word_module");
            Element thesauri_word_module_id=doc.createElement("id");
            Element thesauri_word_module_name_zh=doc.createElement("name_zh");
            Element thesauri_word_module_name_en=doc.createElement("name_en");
            Element thesauri_word_module_description=doc.createElement("description");
            Element thesauri_word_module_sort=doc.createElement("sort");
            thesauri_word_module_id.setTextContent(thesauriWordModule.getId().toString());
            thesauri_word_module_name_zh.setTextContent(thesauriWordModule.getNameZh());
            thesauri_word_module_name_en.setTextContent(thesauriWordModule.getNameEn());
            thesauri_word_module_description.setTextContent(thesauriWordModule.getDescription());
            thesauri_word_module_sort.setTextContent(thesauriWordModule.getSort().toString());
            thesauri_word_module.appendChild(thesauri_word_module_id);
            thesauri_word_module.appendChild(thesauri_word_module_name_zh);
            thesauri_word_module.appendChild(thesauri_word_module_name_en);
            thesauri_word_module.appendChild(thesauri_word_module_description);
            thesauri_word_module.appendChild(thesauri_word_module_sort);
            thesauri_word_data.appendChild(thesauri_word_module);
            //thesauri_word_relations
			List<ThesauriWordRelation> thesauriWordRelation=iWordService.getThesauriWordRelation(twmParam,1,iWordService.getThesauriWordRelationCount(twmParam));
            Element thesauri_word_relations=doc.createElement("thesauri_word_relations");
            for(ThesauriWordRelation twr:thesauriWordRelation){
            	Element thesauri_word_relation=doc.createElement("thesauri_word_relation");
	            Element thesauri_word_relation_id=doc.createElement("id");
	            Element thesauri_word_relation_name_zh=doc.createElement("name_zh");
	            Element thesauri_word_relation_name_en=doc.createElement("name_en");
	            Element thesauri_word_relation_sort=doc.createElement("sort");
	            Element thesauri_word_relation_description=doc.createElement("description");
	            Element thesauri_word_relation_twm_id = doc.createElement("thesauri_word_module_id");
	            thesauri_word_relation_id.setTextContent(twr.getId().toString());
	            thesauri_word_relation_name_zh.setTextContent(twr.getNameZh());
	            thesauri_word_relation_name_en.setTextContent(twr.getNameEn());
	            thesauri_word_relation_sort.setTextContent(twr.getSort().toString());
	            thesauri_word_relation_description.setTextContent(twr.getDescription());
	            thesauri_word_relation_twm_id.setTextContent(twr.getThesauriWordModuleId().toString());
	            thesauri_word_relation.appendChild(thesauri_word_relation_id);
	            thesauri_word_relation.appendChild(thesauri_word_relation_name_zh);
	            thesauri_word_relation.appendChild(thesauri_word_relation_name_en);
	            thesauri_word_relation.appendChild(thesauri_word_relation_sort);
	            thesauri_word_relation.appendChild(thesauri_word_relation_description);
	            thesauri_word_relation.appendChild(thesauri_word_relation_twm_id);
	            thesauri_word_relations.appendChild(thesauri_word_relation);
            }
	            thesauri_word_data.appendChild(thesauri_word_relations);
	            //thesauri_word_categorys
	            List<ThesauriWordCategory> thesauriWordCategory=iWordService.getThesauriWordCategory(twmParam,1,iWordService.getThesauriWordCategoryCount(twmParam));
	            Element thesauri_word_categorys=doc.createElement("thesauri_word_categorys");
	            for(ThesauriWordCategory twc:thesauriWordCategory){
	            	Element thesauri_word_category=doc.createElement("thesauri_word_category");
	            	Element thesauri_word_category_id=doc.createElement("id");
	            	Element thesauri_word_category_name=doc.createElement("category_name");
	            	Element thesauri_word_category_sid=doc.createElement("category_sid");
	            	Element thesauri_word_category_pname=doc.createElement("category_pname");
	            	Element thesauri_word_category_twm_id = doc.createElement("thesauri_word_module_id");
	            	thesauri_word_category_id.setTextContent(twc.getId().toString());
	            	thesauri_word_category_name.setTextContent(twc.getCategoryName());
	            	thesauri_word_category_sid.setTextContent(twc.getCategorySid());
	            	ThesauriWordCategory twcname = iWordService.findThesauriWordCategory(Integer.parseInt(twc.getParentId()));
	            	thesauri_word_category_pname.setTextContent(twcname!=null?twcname.getCategoryName():"");
	            	thesauri_word_category_twm_id.setTextContent(twc.getThesauriWordModuleId().toString());
	            	thesauri_word_category.appendChild(thesauri_word_category_id);
	            	thesauri_word_category.appendChild(thesauri_word_category_name);
	            	thesauri_word_category.appendChild(thesauri_word_category_sid);
	            	thesauri_word_category.appendChild(thesauri_word_category_pname);
	            	thesauri_word_category.appendChild(thesauri_word_category_twm_id);
	            	thesauri_word_categorys.appendChild(thesauri_word_category);
	            }
	            thesauri_word_data.appendChild(thesauri_word_categorys);
	            //thesauri_word_references
	            List<ThesauriWordReference> thesauriWordReference=iWordService.getThesauriWordReference(twmParam,1,iWordService.getThesauriWordReferenceCount(twmParam));
	            Element thesauri_word_references=doc.createElement("thesauri_word_references");
	            for(ThesauriWordReference twre:thesauriWordReference){
	            	Element thesauri_word_reference=doc.createElement("thesauri_word_reference");
	            	Element thesauri_word_reference_id=doc.createElement("id");
	            	Element thesauri_word_thesauri_word_name=doc.createElement("thesauri_word_name");
	            	Element thesauri_word_reference_word_name=doc.createElement("reference_word_name");
	            	Element thesauri_word_reference_rrl=doc.createElement("reference_relation_label");
	            	Element thesauri_word_reference_twm_id = doc.createElement("thesauri_word_module_id");
	            	thesauri_word_reference_id.setTextContent(twre.getId().toString());
	            	ThesauriWord twname = iWordService.findThesauriWord(Integer.parseInt(twre.getThesauriWordId()));
	            	ThesauriWord rwname = iWordService.findThesauriWord(Integer.parseInt(twre.getReferenceWordId()));
	            	thesauri_word_thesauri_word_name.setTextContent(twname!=null?twname.getWordName():"");
	            	thesauri_word_reference_word_name.setTextContent(rwname!=null?rwname.getWordName():"");
	            	thesauri_word_reference_rrl.setTextContent(twre.getReferenceRelationLabel());
	            	thesauri_word_reference_twm_id.setTextContent(twre.getThesauriWordModuleId().toString());
	            	thesauri_word_reference.appendChild(thesauri_word_reference_id);
	            	thesauri_word_reference.appendChild(thesauri_word_thesauri_word_name);
	            	thesauri_word_reference.appendChild(thesauri_word_reference_word_name);
	            	thesauri_word_reference.appendChild(thesauri_word_reference_rrl);
	            	thesauri_word_reference.appendChild(thesauri_word_reference_twm_id);
	            	thesauri_word_references.appendChild(thesauri_word_reference);
	            }
	            thesauri_word_data.appendChild(thesauri_word_references);
	            //thesauri_words
	            List<ThesauriWord> thesauriWord=iWordService.getThesauriWord(twmParam,1,iWordService.getThesauriWordCount(twmParam));
	            Element thesauri_words=doc.createElement("thesauri_words");
	            for(ThesauriWord tw:thesauriWord){
	            	Element thesauri_word=doc.createElement("thesauri_word");
	            	Element thesauri_word_id=doc.createElement("id");
	            	Element thesauri_word_name=doc.createElement("word_name");
	            	Element thesauri_word_itp=doc.createElement("is_top_term");
	            	thesauri_word_id.setTextContent(tw.getId().toString());
	            	thesauri_word_name.setTextContent(tw.getWordName());
	            	thesauri_word_itp.setTextContent(tw.getIsTopTerm());
	            	thesauri_word.appendChild(thesauri_word_id);
	            	thesauri_word.appendChild(thesauri_word_name);
	            	thesauri_word.appendChild(thesauri_word_itp);
	            	if(tw.getWordEnglish() != null){
	            	Element thesauri_word_we=doc.createElement("word_english");
	            	thesauri_word_we.setTextContent(tw.getWordEnglish());
	            	thesauri_word.appendChild(thesauri_word_we);
	            	}
	            	Element thesauri_word_twc_ids = doc.createElement("thesauri_word_category_ids");
	            	thesauri_word_twc_ids.setTextContent(tw.getThesauriWordCategoryIds());
	            	thesauri_word.appendChild(thesauri_word_twc_ids);

	            	if(tw.getWordPinyin() != null){
	            		Element thesauri_word_wp=doc.createElement("word_pinyin");
	            		thesauri_word_wp.setTextContent(tw.getWordPinyin());
	            		thesauri_word.appendChild(thesauri_word_wp);
	            	}
	            	if(tw.getScopeNote() != null && !tw.getScopeNote().equals("")){
	            	Element thesauri_word_sn = doc.createElement("scope_note");
	            	thesauri_word_sn.setTextContent(tw.getScopeNote());
	            	thesauri_word.appendChild(thesauri_word_sn);
	                }
	            	if(tw.getUsageNote() != null && !tw.getUsageNote().equals("")){
	            	Element thesauri_word_un = doc.createElement("usage_note");
	            	thesauri_word_un.setTextContent(tw.getUsageNote());
	            	thesauri_word.appendChild(thesauri_word_un);
					}
	            	if(tw.getHistoricalNote() != null && !tw.getHistoricalNote().equals("")){
	            	Element thesauri_word_hn = doc.createElement("historical_note");
	            	thesauri_word_hn.setTextContent(tw.getHistoricalNote());
	            	thesauri_word.appendChild(thesauri_word_hn);
					}
	            	if(tw.getWordPid() != null){
	            	Element thesauri_word_pname = doc.createElement("word_pname");
		            	if(tw.getWordPid()!=null&&!tw.getWordPid().toString().equals("")){
		            		thesauri_word_pname.setTextContent(iWordService.findThesauriWord(tw.getWordPid()).getWordName());
		            	}else{
		            		thesauri_word_pname.setTextContent("");
		            	}
	            	thesauri_word.appendChild(thesauri_word_pname);
					}
	            	if(tw.getWordFormal() != null){
	            	Element thesauri_word_wf = doc.createElement("word_formal");
	            	thesauri_word_wf.setTextContent(tw.getWordFormal().toString());
	            	thesauri_word.appendChild(thesauri_word_wf);
	            	}
	            	
	            	Element thesauri_word_twm_id = doc.createElement("thesauri_word_module_id");
	            	thesauri_word_twm_id.setTextContent(tw.getThesauriWordModuleId().toString());
	            	thesauri_word.appendChild(thesauri_word_twm_id);
	            	thesauri_words.appendChild(thesauri_word);
	            }
	            thesauri_word_data.appendChild(thesauri_words);
			
			//step9:获得一个TransformerFactory对象  
			TransformerFactory transformerFactory = TransformerFactory.newInstance();  
			//step10:获得一个Transformer对象  
			Transformer transformer = transformerFactory.newTransformer();  
			//step11:把document对象用一个DOMSource对象包装起来  
			Source xmlSource = new DOMSource(doc);  
			//step12:建立一个存储目标对象  
			//获取服务器地址
			ServletContext sc = request.getSession().getServletContext();
			String dir =sc.getRealPath("/XMLFile/");
			File dirFile = new File(dir);
			if (!dirFile.exists()) {
				dirFile.mkdirs();
			}
			
			String random = System.nanoTime()+".xml";
			File downFile = new File(dirFile, random);
			Result outputTarget = new StreamResult(downFile);  
			//step13:生成相应的xml文件  
			transformer.setOutputProperty(OutputKeys.INDENT, "yes");  
			transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); 
			transformer.transform(xmlSource, outputTarget);
			
			// 下载文件
			FileDownloadUtil.download(downFile, thesauriWordModule.getNameEn()+".xml", request, response);
			
		} catch (Exception e1) {
			e1.printStackTrace();
		} 
		
	}
	//词表注解导出
	@RequestMapping("downloadNote")
	public void downloadNote(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String fileName = "vocabularyNote.xml";
		String path = request.getSession().getServletContext().getRealPath("/template/");
		generalWordExport(request, response, fileName, path);

	}
	//范畴注解导出
	@RequestMapping("downloadScope")
	public void downloadScope(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String fileName = "vocabularyScope.xml";
		String path = request.getSession().getServletContext().getRealPath("/template/");
		generalWordExport(request, response, fileName, path);
		
	}
	//字典注解导出
	@RequestMapping("downloadDict")
	public void downloadDict(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String fileName = "vocabularyDict.xml";
		String path = request.getSession().getServletContext().getRealPath("/template/");
		generalWordExport(request, response, fileName, path);
		
	}
	public void generalWordExport(HttpServletRequest request,
			HttpServletResponse response, String fileName, String path)
			throws Exception {
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");
		response.setHeader("Content-Disposition", "attachment;fileName="
				+ fileName);
		try {
			// 这个download目录为啥建立在classes下的
			InputStream inputStream = new FileInputStream(new File(path + "/"
					+ File.separator + fileName));
			OutputStream os = response.getOutputStream();
			byte[] b = new byte[2048];
			int length;
			while ((length = inputStream.read(b)) > 0) {
				os.write(b, 0, length);
			}
			// 这里主要关闭。
			os.close();
			inputStream.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	//批量操作客户级别
	@RequestMapping("bassOperation")
	public void toBassOperation(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String[] classesIds =request.getParameterValues("id");
		String keHuJiBie=request.getParameter("keHuJiBie");
		String classesEn = request.getParameter("classesEn");
		List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
		String returnid="yes";
		for (int i = 0; i < classesIds.length; i++) {
			dataList.add(dynamicService.findDynamicData(classesEn, classesIds[i]));
		}
		for (int i = 0; i < dataList.size(); i++) {
			Map dynamic = dataList.get(i);
			String id = dynamic.get("id").toString();
				dynamic.remove("updateTime");
				dynamic.remove("updateUserId");
				dynamic.remove("status");
				dynamic.remove("version");
				dynamic.remove("id");
				dynamic.remove("createTime");
				dynamic.remove("submitTime");
				dynamic.remove("createUserId");
				dynamic.remove("submitUserId");
				dynamic.remove("dataSource");
				dynamic.remove("classesId");
				dynamic.remove("updateOrgId");
				dynamic.remove("createOrgId");
				dynamic.remove("submitOrgId");
				dynamic.put("ke_hu_ji_bie", keHuJiBie);
				HashMap data = new HashMap();
				for(Object key: dynamic.keySet()){
					data.put(key.toString(), dynamic.get(key));
				}
				Integer departmentid =(Integer) request.getSession().getAttribute("userid");
				String updateUserId = departmentid.toString();
				String status = "0";
				String version = "1.0";
				String updateTime = DateUtils.getDateTime();
				try {
					dynamicService.editDynamicData(classesEn, data, updateTime, updateUserId, status, version, id);
					//dynamicService.submitDynamicData(classesEn, updateTime,updateUserId, id);
				} catch (Exception e) {
					returnid="no";
				}
				
		}
		List<String> r = new ArrayList<String>();
		r.add(returnid);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	//审核
	@RequestMapping("auditStatus")
	public void auditStatus(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String[] classesIds =request.getParameterValues("id");
		String status=request.getParameter("status");
		String classesEn = request.getParameter("classesEn");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");
		List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
		String returnid="yes";
		for (int i = 0; i < classesIds.length; i++) {
			if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
				dataList.add(dynamicService.findDynamicData(classesEn, classesIds[i],databaseName,chartName));
			}else{
				dataList.add(dynamicService.findDynamicData(classesEn, classesIds[i]));
			}
		}
		for (int i = 0; i < dataList.size(); i++) {
			Map dynamic = dataList.get(i);
			String id = dynamic.get("id").toString();
				dynamic.remove("updateTime");
				dynamic.remove("updateUserId");
				dynamic.remove("status");
				dynamic.remove("version");
				dynamic.remove("id");
				dynamic.remove("createTime");
				dynamic.remove("submitTime");
				dynamic.remove("createUserId");
				dynamic.remove("submitUserId");
				dynamic.remove("dataSource");
				dynamic.remove("classesId");
				dynamic.remove("updateOrgId");
				dynamic.remove("createOrgId");
				dynamic.remove("submitOrgId");
				HashMap data = new HashMap();
				for(Object key: dynamic.keySet()){
					data.put(key.toString(), dynamic.get(key));
				}
				Integer departmentid =(Integer) request.getSession().getAttribute("userid");
				String updateUserId = departmentid.toString();
				String version = "1.0";
				String updateTime = DateUtils.getDateTime();
				try {
					if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
						dynamicService.editDynamicData(classesEn, data, updateTime, updateUserId, status, version, id,databaseName,chartName);
					}else{
						dynamicService.editDynamicData(classesEn, data, updateTime, updateUserId, status, version, id);
					}
					//dynamicService.submitDynamicData(classesEn, updateTime,updateUserId, id);
				} catch (Exception e) {
					returnid="no";
				}
				
		}
		List<String> r = new ArrayList<String>();
		r.add(returnid);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	
	/**
	 * @author zf
	 * 统一检索--》权重配置 
	 * 2017年4月5日19:55:09
	 * 
	 *    start
	 */
	
	//字段权重新增以及修改
	@RequestMapping("fieldAddUpload")
	public void fieldAddUpload(SearchWeightFields searchWeightFields,HttpServletResponse response) throws Exception {
		String createTime = DateUtils.getDateTime();
		searchWeightFields.setCreateTime(createTime);
		searchWeightFields.setStatus(0);
		
		String pd="yes";
		try {
			if("1".equals(searchWeightFields.getRange())){
				HashMap<String,Object> params = new HashMap<String, Object>();
				params.put("=,nameEn", searchWeightFields.getNameEn());
				params.put("=,classesEn", searchWeightFields.getClassesEn());
				if(searchWeightFields.getId() != 0){
					params.put("!,id", searchWeightFields.getId());
				}
				if(publicService.getSearchWeightFieldsCount(params) == 0){
					if(searchWeightFields.getId() != 0){
						baseService.editSearchWeightFields(searchWeightFields);
					}else{
						baseService.saveSearchWeightFields(searchWeightFields);
					}
				}else{
					pd = "exist";
				}
			}else{
				HashMap<String,Object> params = new HashMap<String, Object>();
				params.put("=,nameEn", searchWeightFields.getNameEn());
				params.put("=,`range`", searchWeightFields.getRange());
				if(searchWeightFields.getId() != 0){
					params.put("!,id", searchWeightFields.getId());
				}
				if(publicService.getSearchWeightFieldsCount(params) == 0){
					if(searchWeightFields.getId() != 0){
						baseService.editSearchWeightFields(searchWeightFields);
					}else{
						baseService.saveSearchWeightFields(searchWeightFields);
					}
				}else{
					pd = "exist";
				}
			}
			//if(id.equals("0")){
				
//			}else{
//				searchWeightFields.setId(Integer.parseInt(id));
//				baseService.editSearchWeightFields(searchWeightFields);
//			}
		} catch (Exception e) {
			pd="no";
			e.printStackTrace();
		}
		super.pringWriterToPage(toJsonString(pd), "application/json", response);
	}
	//字段列表显示
	@RequestMapping("queryfieldList")
	public void queryfieldList(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String nameZh=request.getParameter("nameZh");
		String nameEn = request.getParameter("nameEn");
//		String isCommonDataProperty = request.getParameter("isCommonDataProperty");
		String scope = request.getParameter("scope");
		String parentClassid = request.getParameter("parentClassid");
		String page = request.getParameter("page");
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		if(StringUtils.isNotBlank(nameZh)){
			queryParams.put("%,nameZh", nameZh);
		}
		if(StringUtils.isNotBlank(nameEn)){
			queryParams.put("%,nameEn", nameEn);
		}
//		if(isCommonDataProperty != null && !"".equals(isCommonDataProperty)){
//			queryParams.put("=,isCommonDataProperty", isCommonDataProperty);
//		}
		// `该符号用来转义mysql关键字  比如range
		if(StringUtils.isNotBlank(scope)){
			queryParams.put("=,`range`", scope);
		}
		if(parentClassid != null && !"".equals(parentClassid)){
			queryParams.put("%,classesEn", parentClassid);
		}
		
		List<SearchWeightFields> SearchWeightFields = publicService.getSearchWeightFields(queryParams, Integer.parseInt(page), 15);
		for (int i = 0; i < SearchWeightFields.size(); i++) {
			SearchWeightFields searchWeightFields = SearchWeightFields.get(i);
			if("1".equalsIgnoreCase(searchWeightFields.getRange())){
				String classesid = searchWeightFields.getClassesEn();
				Classes findClasses = publicService.findClasses(Integer.parseInt(classesid));
				searchWeightFields.setClassesEn(findClasses.getNameZh());
			}
		}
		int fieldsCount =publicService.getSearchWeightFieldsCount(queryParams);
		HashMap<String, Object> map=new LinkedHashMap<String, Object>();
		map.put("text", SearchWeightFields);
		map.put("fieldsCount", (int)Math.ceil(Double.valueOf(fieldsCount)/15));
		String result = formatToJson(map);
		super.pringWriterToPage(result, "application/json", response);
	}
	//字段列表修改查询
	@RequestMapping("fieldAddUploadQuery")
	public void fieldAddUploadQuery(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id=request.getParameter("id");
		SearchWeightFields SearchWeightFields =publicService.findSearchWeightFields(Integer.parseInt(id));
		String result = toJsonString(SearchWeightFields);
		super.pringWriterToPage(result, "application/json", response);
	}
	//字段列表删除
	@RequestMapping("fieldDelete")
	public void fieldDelete(SearchWeightFields searchWeightFields,HttpServletResponse response) throws Exception {
		String result = "success";
		try {
			baseService.deleteSearchWeightFields(searchWeightFields);
		} catch (Exception e) {
			result = "fail";
			e.printStackTrace();
		}
		super.pringWriterToPage(toJsonString(result), "application/json", response);
	}
	//自定义权重新增以及修改
	@RequestMapping("customsAddUpload")
	public void customsAddUpload(SearchWeightCustoms searchWeightCustoms,HttpServletResponse response) throws Exception {
		String createTime = DateUtils.getDateTime();
		searchWeightCustoms.setCreateTime(createTime);
		searchWeightCustoms.setStatus(0);
		String pd="yes";
		try {
			HashMap<String,Object> params = new HashMap<String, Object>();
			params.put("=,nameEn", searchWeightCustoms.getNameEn());
			if("1".equals(searchWeightCustoms.getRange())){
				params.put("=,classesEn", searchWeightCustoms.getClassesEn());
			}else{
				params.put("=,`range`", searchWeightCustoms.getRange());
			}
			if(searchWeightCustoms.getId() != 0){
				params.put("!,id", searchWeightCustoms.getId());
			}
			if(publicService.getSearchWeightCustomsCount(params) == 0){
				if(searchWeightCustoms.getId() != 0){
					baseService.editSearchWeightCustoms(searchWeightCustoms);
				}else{
					baseService.saveSearchWeightCustoms(searchWeightCustoms);
				}
			}else{
				pd = "exist";
			}
		} catch (Exception e) {
			pd="no";
			e.printStackTrace();
		}
		super.pringWriterToPage(toJsonString(pd), "application/json", response);
	}
	//自定义列表显示
	@RequestMapping("querycustomsList")
	public void querycustomsList(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String nameZh=request.getParameter("nameZh");
		String nameEn = request.getParameter("nameEn");
//		String isCommonDataProperty = request.getParameter("isCommonDataProperty");
		String scope = request.getParameter("scope");
		String fieldValue = request.getParameter("fieldValue");
		String parentClassid = request.getParameter("parentClassid");
		String page = request.getParameter("page");
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		if(StringUtils.isNotBlank(nameZh)){
			queryParams.put("%,nameZh", nameZh);
		}
		if(StringUtils.isNotBlank(nameEn)){
			queryParams.put("%,nameEn", nameEn);
		}
//		if(isCommonDataProperty != null && !"".equals(isCommonDataProperty)){
//			queryParams.put("=,isCommonDataProperty", isCommonDataProperty);
//		}
		if(StringUtils.isNotBlank(scope)){
			queryParams.put("=,`range`", scope);
		}
		if(StringUtils.isNotBlank(parentClassid)){
			queryParams.put("=,classesEn", parentClassid);
		}
		if(StringUtils.isNotBlank(fieldValue)){
			queryParams.put("%,fieldValue", fieldValue);
		}
		List<SearchWeightCustoms> searchWeightCustomsList =publicService.getSearchWeightCustoms(queryParams, Integer.parseInt(page), 15);
		for (int i = 0; i < searchWeightCustomsList.size(); i++) {
			SearchWeightCustoms searchWeightCustoms = searchWeightCustomsList.get(i);
			if("1".equals(searchWeightCustoms.getRange())){
				String classesid = searchWeightCustoms.getClassesEn();
				Classes findClasses = publicService.findClasses(Integer.parseInt(classesid));
				searchWeightCustoms.setClassesEn(findClasses.getNameZh());
			}
		}
		int customsCount= publicService.getSearchWeightCustomsCount(queryParams);
		HashMap<String, Object> map=new LinkedHashMap<String, Object>();
		map.put("text", searchWeightCustomsList);
		map.put("customsCount", (int)Math.ceil(Double.valueOf(customsCount)/15));
		String result = formatToJson(map);
		super.pringWriterToPage(result, "application/json", response);
	}
	//自定义列表修改查询
	@RequestMapping("customsAddUploadQuery")
	public void customsAddUploadQuery(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id=request.getParameter("id");
		SearchWeightCustoms searchWeightCustoms =publicService.findSearchWeightCustoms(Integer.parseInt(id));
		String result = toJsonString(searchWeightCustoms);
		super.pringWriterToPage(result, "application/json", response);
	}
	//自定义列表删除
	@RequestMapping("customsDelete")
	public void customsDelete(SearchWeightCustoms searchWeightCustoms,HttpServletResponse response) throws Exception {
		String result = "success";
		try{
			baseService.deleteSearchWeightCustoms(searchWeightCustoms);
		}catch(Exception e){
			result= "fail";
		}
		super.pringWriterToPage(toJsonString(result), "application/json", response);
	}
	
	/**
	 * @author zf
	 * 排序策略
	 * 2017年4月7日10:20:49
	 */
	//排序新增以及修改
	@RequestMapping("sortAddUpload")
	public void sortAddUpload(SearchSortRule searchSortRule,HttpServletResponse response) throws Exception {
		String pd="yes";
		try {
			if(searchSortRule.getScope() == 1){
				HashMap<String,Object> params = new HashMap<String, Object>();
				params.put("=,nameEn", searchSortRule.getNameEn());
				params.put("=,classesId", searchSortRule.getClassesId());
				if(searchSortRule.getId() != 0){
					params.put("!,id", searchSortRule.getId());
				}
				if(publicService.getSearchSortRuleCount(params) == 0){
					if(searchSortRule.getId() != 0){
						baseService.editSearchSortRule(searchSortRule);
					}else{
						baseService.saveSearchSortRule(searchSortRule);
					}
				}else{
					pd = "exist";
				}
			}else{
				HashMap<String,Object> params = new HashMap<String, Object>();
				params.put("=,nameEn", searchSortRule.getNameEn());
				params.put("=,scope", searchSortRule.getScope());
				if(searchSortRule.getId() != 0){
					params.put("!,id", searchSortRule.getId());
				}
				if(publicService.getSearchSortRuleCount(params) == 0){
					if(searchSortRule.getId() != 0){
						baseService.editSearchSortRule(searchSortRule);
					}else{
						baseService.saveSearchSortRule(searchSortRule);
					}
				}else{
					pd = "exist";
				}
			}
		} catch (Exception e) {
			pd="no";
			e.printStackTrace();
		}
		super.pringWriterToPage(toJsonString(pd), "application/json", response);
	}
	//排序列表显示
	@RequestMapping("querysortList")
	public void querysortList(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String nameZh=request.getParameter("nameZh");
		String nameEn = request.getParameter("nameEn");
		String page = request.getParameter("page");
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		if(nameZh != null && !"".equals(nameZh)){
			queryParams.put("%,nameZh", nameZh);
		}
		if(nameEn != null && !"".equals(nameEn)){
			queryParams.put("%,nameEn", nameEn);
		}
		queryParams.put("^,sort", "asc");
		List<SearchSortRule> SearchSortRule =publicService.getSearchSortRule(queryParams, Integer.parseInt(page), 15);
		for(SearchSortRule rule:SearchSortRule){
			if(rule.getScope() == 1){
				rule.setClassesId(publicService.findClasses(Integer.parseInt(rule.getClassesId())).getNameZh());
			}
		}
		int sortCount= publicService.getSearchSortRuleCount(queryParams);
		HashMap<String, Object> map=new LinkedHashMap<String, Object>();
		map.put("text", SearchSortRule);
		map.put("sortCount", (int)Math.ceil(Double.valueOf(sortCount)/15));
		String result = formatToJson(map);
		super.pringWriterToPage(result, "application/json", response);
	}
	//排序单个查询
	@RequestMapping("querySortUplaod")
	public void querySortUplaod(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id=request.getParameter("id");
		SearchSortRule searchSortRule =publicService.findSearchSortRule(Integer.parseInt(id));
		String result = toJsonString(searchSortRule);
		super.pringWriterToPage(result, "application/json", response);
		
	}
	//排序删除
	@RequestMapping("deleteSort")
	public void deleteSort(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id=request.getParameter("id");
		SearchSortRule searchSortRule = new SearchSortRule();
		searchSortRule.setId(Integer.parseInt(id));
		String msg = "success";
		try{
			baseService.deleteSearchSortRule(searchSortRule);
		}catch(Exception e){
			msg = "fail";
		}
		super.pringWriterToPage(toJsonString(msg), "application/json", response);
	}
	//排序公共数据属性组
	@RequestMapping("commonDataPropertyZtree")
	public void toCommonDataPropertyZtree(HttpServletResponse response,HttpServletRequest request) throws Exception {
		String classid=request.getParameter("id");
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
			if("0".equals(classid)){
				List<CommonDataProperty> list1 = publicService.getCommonDataProperty();
				for (int j = 0; j < list1.size(); j++) {
					mp = new LinkedHashMap<String, Object>();
					CommonDataProperty commonDataProperty = list1.get(j);
					mp.put("id", commonDataProperty.getId());
					mp.put("name", commonDataProperty.getNameZh());
					mp.put("pId", 0);
					r.add(mp);
				}
			}
			else{
				List<DataProperty> dataPropertyList = publicService.getDataProperty(publicService.findClasses(Integer.parseInt(classid)));
				for (int i = 0; i < dataPropertyList.size(); i++) {
					mp = new LinkedHashMap<String, Object>();
					DataProperty dataProperty =dataPropertyList.get(i);
					mp.put("id", dataProperty.getId());
					mp.put("name", dataProperty.getNameZh());
					mp.put("pId", 0);
					r.add(mp);
		}
	}		
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	/**
	 * @author zf
	 * 热搜词
	 * 2017年4月7日10:20:49
	 */
	//热搜词新增以及修改
	@RequestMapping("hotwordsAddUpload")
	public void hotwordsAddUpload(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id=request.getParameter("id");
		String wordName=request.getParameter("wordName");
		String linkUrl = request.getParameter("linkUrl");
		String fontColor = request.getParameter("fontColor");
		String fontSize = request.getParameter("fontSize");
		String sort = request.getParameter("sort");
		
		SearchHotwords searchHotwords = new SearchHotwords();
		searchHotwords.setFontColor(fontColor);
		searchHotwords.setFontSize(Double.valueOf(fontSize));
		searchHotwords.setLinkUrl(linkUrl);
		searchHotwords.setSort(Integer.parseInt(sort));
		searchHotwords.setWordName(wordName);
		searchHotwords.setStatus(0);
		String pd="yes";
		try {
			if(id.equals("0")){
				baseService.saveSearchHotwords(searchHotwords);
			}else{
				searchHotwords.setId(Integer.parseInt(id));
				baseService.editSearchHotwords(searchHotwords);
			}
		} catch (Exception e) {
			pd="no";
			e.printStackTrace();
		}
		List<String> r = new ArrayList<String>();
		r.add(pd);
		String result = formatToJson(r);
		super.pringWriterToPage(result, "application/json", response);
	}
	//热搜词列表显示
	@RequestMapping("queryhotwordsList")
	public void queryhotwordsList(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String nameZh=request.getParameter("nameZh");
		String page = request.getParameter("page");
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		if(nameZh != null && !"".equals(nameZh)){
			queryParams.put("%,wordName", nameZh);
		}
		queryParams.put("^,sort", "asc");
		List<SearchHotwords> searchHotwords =publicService.getSearchHotwords(queryParams, Integer.parseInt(page), 15);
		int hotwordsCount= publicService.getSearchHotwordsCount(queryParams);
		HashMap<String, Object> map=new LinkedHashMap<String, Object>();
		map.put("text", searchHotwords);
		map.put("hotwordsCount", (int)Math.ceil(Double.valueOf(hotwordsCount)/15));
		String result = formatToJson(map);
		super.pringWriterToPage(result, "application/json", response);
	}
	//热搜词单个查询
	@RequestMapping("queryhotwordsUplaod")
	public void queryhotwordsUplaod(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id=request.getParameter("id");
		SearchHotwords searchHotwords =publicService.findSearchHotwords(Integer.parseInt(id));
		String result = formatToJson(searchHotwords);
		super.pringWriterToPage(result, "application/json", response);
		
	}
	//热搜词删除
	@RequestMapping("deleteHotwords")
	public void deleteHotwords(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id=request.getParameter("id");
		SearchHotwords searchHotwords =publicService.findSearchHotwords(Integer.parseInt(id));
		baseService.deleteSearchHotwords(searchHotwords);
		String result = formatToJson(searchHotwords);
		super.pringWriterToPage(result, "application/json", response);
	}
	//热搜词查询全部
	@RequestMapping("queryHotwordsAll")
	public void queryHotwordsAll(HttpServletRequest request,HttpServletResponse response) throws Exception {
		List<SearchHotwords> searchHotwords =publicService.getSearchHotwords();
		String result = formatToJson(searchHotwords);
		super.pringWriterToPage(result, "application/json", response);
	}
	/**
	 * 新闻管理
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	// 统一检索---》新闻查询
    @RequestMapping("searchNewsSettingList")
    public void queryBaiKeNews(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        String page = request.getParameter("page");
        String title = request.getParameter("title");
        String source = request.getParameter("source");
        String submitUser = request.getParameter("submitUser");
        String status = request.getParameter("status");
        String newsCategory = request.getParameter("newsCategory");
        String recommend = request.getParameter("recommend");
        
        //路径
        String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
        HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
        if(title != null && !"".equals(title)){
            queryParams.put("title", title);
        }
        if(source != null && !"".equals(source)){
            queryParams.put("source", source);
        }
        if(submitUser != null && !"".equals(submitUser)){
            queryParams.put("submit_user", submitUser);
        }
        if(status != null && !"".equals(status)){
            queryParams.put("=status", status);
        }
        if(recommend != null && !"".equals(recommend)){
        	queryParams.put("=recommend", recommend);
        }
        if(newsCategory != null && !"".equals(newsCategory)){
        	queryParams.put("=news_category", newsCategory);
        }
        
        List<Map<String, Object>>  list =dynamicService.getDynamicData("news", queryParams, "id", "desc", Integer.parseInt(page), 15);
		//页数
		long pageCount = dynamicService.getDynamicCount("news", queryParams);
		int ye =(int)Math.ceil(Double.valueOf(pageCount)/15);
		HashMap<String, Object> queryDictParams =null;
        for (int i = 0; i < list.size(); i++) {
        	Map<String, Object> hasmap = list.get(i);
            if(hasmap.get("cover") != null && !"".equals(hasmap.get("cover"))){
            	hasmap.put("cover", uploadPath +hasmap.get("cover"));
            }
            queryDictParams = new HashMap<String, Object>();
            queryDictParams.put("=,value", hasmap.get("news_category"));
            queryDictParams.put("=,dict_id", "10");
            List<DictItem>  dictItem= publicService.getDictItem(queryDictParams, 1, 1);
            if(dictItem != null && dictItem.size() > 0){
            	hasmap.put("newsCategoryName", dictItem.get(0).getNameZh());
            }else{
            	hasmap.put("newsCategoryName", "");
            }
        }
        HashMap<String, Object> conditions = new HashMap<String, Object>();
        conditions.put("news", list);
        conditions.put("ye", ye);
        String result = formatToJson(conditions);
        super.pringWriterToPage(result.toString(), "application/json", response);
    }
    // 统一检索-->新增或修改
    @RequestMapping("addOrUploadSearchNews")
    public void addBaikeNews(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        String title = request.getParameter("title");
        String summary = request.getParameter("summary");
        String coverImg = request.getParameter("coverImg");
        String submitTime = request.getParameter("submitTime");
        String source = request.getParameter("source");
        String submitUser = request.getParameter("submitUser");
        String status = request.getParameter("status");
        String newsCategory = request.getParameter("newsCategory");
        String recommend = request.getParameter("recommend");
        String text = request.getParameter("text");
        String id = request.getParameter("id");
        
        Integer departmentid =(Integer) request.getSession().getAttribute("userid");
        String createUserId = departmentid.toString();
		String version = "1.0";
		String createTime = DateUtils.getDateTime();
		String dataSource = "1";
		HashMap<String, Object> dynamicData = new HashMap<String, Object>();
		dynamicData.put("title", title);
		dynamicData.put("summary", summary);
		dynamicData.put("date", submitTime);
		dynamicData.put("source", source);
		dynamicData.put("author", submitUser);
		dynamicData.put("news_category", newsCategory);
		dynamicData.put("recommend", recommend);
        List<String> r = new ArrayList<String>();
        String areturn="yes";
        try {
            if(id != null && !"".equals(id)){
                //获取服务器地址
                String serversPath =  XxlConfClient.get("dal.file.server", "");
                coverImg = coverImg.replaceAll(serversPath, "");
                dynamicData.put("text", text.replaceAll(serversPath, ""));
                dynamicData.put("cover", coverImg);
                dynamicService.editDynamicData("news", dynamicData, createTime, createUserId, status, version,id);
            }else{
                //获取服务器地址
                String serversPath =  XxlConfClient.get("dal.file.server", "")+"/";
                coverImg = coverImg.replaceAll(serversPath, "");
                dynamicData.put("text", text.replaceAll(serversPath, ""));
                dynamicData.put("cover", coverImg);
                dynamicService.addDynamicData("news", dynamicData, createTime, createUserId, status, version, "20", dataSource);
            }
        } catch (Exception e) {
            areturn = "no";
            e.printStackTrace();
        }
        r.add(areturn);
        String result = formatToJson(r);
        super.pringWriterToPage(result.toString(), "application/json", response);
    }
    // 统一检索-->修改
    @RequestMapping("uploadSearchNews")
    public void uploadBaikeNews(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        //获取服务器地址
        String serversPath =  XxlConfClient.get("dal.file.server", "");
        String id =request.getParameter("id");
//        CmsNews searchNews = publicService.findCmsNews(Integer.parseInt(id));
//        searchNews.setCoverImg(serversPath+searchNews.getCoverImg());
//        searchNews.setText(CommonUrl.addPrefixPath("src", searchNews.getText(), serversPath+"/"));
//        String result = formatToJson(searchNews);
//        SearchNews searchNews = publicService.findSearchNews(Integer.parseInt(id));
//        searchNews.setCoverImg(serversPath+searchNews.getCoverImg());
//        searchNews.setText(CommonUrl.addPrefixPath("src", searchNews.getText(), serversPath+"/"));
//        String result = formatToJson(searchNews);
//        SearchNews searchNews = publicService.findSearchNews(Integer.parseInt(id));
        Map<String, Object> hasmap = dynamicService.findDynamicData("news", id);
        if(hasmap.get("cover") != null && !"".equals(hasmap.get("cover"))){
        	hasmap.put("cover", serversPath +hasmap.get("cover"));
        }
        HashMap<String, Object> queryDictParams = new HashMap<String, Object>();
        queryDictParams.put("=,value", hasmap.get("news_category"));
        queryDictParams.put("=,dict_id", "10");
        List<DictItem>  dictItem= publicService.getDictItem(queryDictParams, 1, 1);
        if(dictItem != null && dictItem.size() > 0){
        	hasmap.put("newsCategoryName", dictItem.get(0).getNameZh());
        }else{
        	hasmap.put("newsCategoryName", "");
        }
        hasmap.put("text", CommonUrl.addPrefixPath("src",hasmap.get("text"), serversPath+"/"));
        String result = formatToJson(hasmap);
        super.pringWriterToPage(result.toString(), "application/json", response);
    }
    // 管理新闻-->删除
    @RequestMapping("deleteSearchNews")
    public void deleteSearchNews(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        String id =request.getParameter("id");
        List<String> r = new ArrayList<String>();
        String rString ="yes";
        try {
        	Map<String, Object>  aDynamicData=dynamicService.findDynamicData("news", id);
    		dynamicService.deleteDynamicData("news", aDynamicData);
        } catch (Exception e) {
            rString = "no";
            e.printStackTrace();
        }
        r.add(rString);
        String result = formatToJson(r);
        super.pringWriterToPage(result.toString(), "application/json", response);
    }
	
    /**
     * @author zf
     * 2017年11月25日16:30:23
     * 索引管理
     * 
     */
	
    // 索引管理-->查询知识库
    @RequestMapping("getKnowledgeClassesSolrData")
    public void getKnowledgeClassesSolrData(HttpServletRequest request,HttpServletResponse response) throws Exception {
        List<LinkedHashMap<String, Object>> r = new ArrayList<LinkedHashMap<String, Object>>();
        LinkedHashMap<String, Object> data = null;
        HashMap<String, Object> queryRepositoryCountParams = null;
        List<Classes> classesList = publicService.getClasses();
        for (int i = 0; i < classesList.size(); i++) {
        	data = new LinkedHashMap<String, Object>();
        	Classes classes = classesList.get(i);
        	queryRepositoryCountParams = new HashMap<String, Object>();
			queryRepositoryCountParams.put("=,classes_en", classes.getNameEn());
			List<ShardingRepositoryCount> ShardingRepositoryCountList = publicService.getShardingRepositoryCount(queryRepositoryCountParams, 1, publicService.getShardingRepositoryCountCount(queryRepositoryCountParams));
			if(null != ShardingRepositoryCountList && ShardingRepositoryCountList.size()>0){
				int dynamicCount=0;
				for (int j = 0; j < ShardingRepositoryCountList.size(); j++) {
					ShardingRepositoryCount shardingRepositoryCount = ShardingRepositoryCountList.get(j);
					dynamicCount = dynamicCount+shardingRepositoryCount.getDataCount();
				}
	        	long searchFacet = searchService.searchCount("$type:"+classes.getNameEn(), null);
	        	data.put("dynamicCount", dynamicCount);
	        	data.put("searchFacet", searchFacet);
	        	data.put("nameEn", classes.getNameEn());
	        	data.put("nameZh", classes.getNameZh());
	        	data.put("id", classes.getId());
	        	r.add(data);
			}else{
				long dynamicCount = dynamicService.getDynamicCount(classes.getNameEn(), null);
	        	long searchFacet = searchService.searchCount("$type:"+classes.getNameEn(), null);
	        	data.put("dynamicCount", dynamicCount);
	        	data.put("searchFacet", searchFacet);
	        	data.put("nameEn", classes.getNameEn());
	        	data.put("nameZh", classes.getNameZh());
	        	data.put("id", classes.getId());
	        	r.add(data);
			}
		}
        String result = formatToJson(r);
        super.pringWriterToPage(result.toString(), "application/json", response);
    }
    // 索引管理-->查询其他数据
    @RequestMapping("getRestsSolrData")
    public void getRestsSolrData(HttpServletRequest request,HttpServletResponse response) throws Exception {
    	LinkedHashMap<String, Object>  data = new LinkedHashMap<String, Object>();
    	long solrbaikeCount = searchService.searchBaikeCount("*:*");
    	int BaikeEntryCount = baikeService.getBaikeEntryCount(null);
    	
    	long solrwordCount = searchService.searchWordCount("*:*");
    	int generalWordCount = iWordService.getGeneralWordCount(null);
    	int thesauriWordCount = iWordService.getThesauriWordCount(null);
    	
    	long solrkwCount = searchService.searchKwCount("*:*");
    	
    	long solrindexingCount = searchService.searchIndexingCount("*:*",null);
    	data.put("solrbaikeCount", solrbaikeCount);
    	data.put("BaikeEntryCount", BaikeEntryCount);
    	data.put("solrwordCount", solrwordCount);
    	data.put("wordCount", thesauriWordCount+generalWordCount);
    	data.put("solrkwCount", solrkwCount);
    	data.put("solrindexingCount", solrindexingCount);
    	String result = formatToJson(data);
    	super.pringWriterToPage(result.toString(), "application/json", response);
    }
    
    // 索引管理-->删除全部索引
    @RequestMapping("deleteSolrAllIndexes")
    public void deleteSolrAllIndexes(HttpServletRequest request,HttpServletResponse response) throws Exception {
    	String type =request.getParameter("type");
    	String classesEn =request.getParameter("classesEn");
    	LinkedHashMap<String, Object>  data = new LinkedHashMap<String, Object>();
    	try {
			if("baike".equals(type)){
				dynamicService.deleteAllBaikeIndex();
			}else if("word".equals(type)){
				dynamicService.deleteAllWordIndex();
			}else if("keywords".equals(type)){
				dynamicService.deleteAllKwIndex();;
			}else if("indexWeight".equals(type)){
				dynamicService.deleteAllIndexWeightIndex();;
			}else if("Knowledge".equals(type)){
				dynamicService.deleteIndexByClassesEn(classesEn);
			}
			data.put("data", "yes");
		} catch (Exception e) {
			data.put("data", "no");
		}
    	String result = formatToJson(data);
    	super.pringWriterToPage(result.toString(), "application/json", response);
    }
    
    // 索引管理-->表达式删除索引
    @RequestMapping("deleteSolrIndexes")
    public void deleteSolrIndexes(HttpServletRequest request,HttpServletResponse response) throws Exception {
    	String type =request.getParameter("type");
    	String queryStr =request.getParameter("queryStr");
    	LinkedHashMap<String, Object>  data = new LinkedHashMap<String, Object>();
    	try {
			if("baike".equals(type)){
				dynamicService.deleteBaikeIndexByCondition(queryStr);
			}else if("word".equals(type)){
				dynamicService.deleteWordIndexByCondition(queryStr);
			}else if("keywords".equals(type)){
				dynamicService.deleteKwIndexByCondition(queryStr);;
			}else if("indexWeight".equals(type)){
				dynamicService.deleteIndexWeightIndexByCondition(queryStr);;
			}else if("Knowledge".equals(type)){
				dynamicService.deleteIndexByCondition(queryStr);
			}
			data.put("data", "yes");
		} catch (Exception e) {
			data.put("data", "no");
		}
    	String result = formatToJson(data);
    	super.pringWriterToPage(result.toString(), "application/json", response);
    }
    
    
	/**
	 * 上传接口
	 * @param request
	 * @param response
	 */
	@RequestMapping("ueditorController")
	public void controller(HttpServletRequest request,HttpServletResponse response) {
        try {
        	response.setContentType("application/json");   
    		request.setCharacterEncoding( "utf-8" );
    		response.setHeader("Content-Type" , "text/html");
            String rootPath = request.getSession().getServletContext().getRealPath("/");
        	String a = request.getRequestURI();
            String exec = new ActionEnter(request, rootPath).exec();
            String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
            JSONObject jb = JSONObject.fromObject(exec);
    	    Map map = (Map)jb;
    	    for (Object key : map.keySet()) {
    	    	String url =uploadPath+map.get(key).toString();
    	    	if("url".equals(key)){
    	    		map.put(key, url);
    	    	}
    	    }
    	    exec = JSONObject.fromObject(map).toString();
            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
            writer.close();
        } catch (Exception e) {
                e.printStackTrace();
        }
	}
	/**
	 * 知识字典发布按钮
	 * @param request
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping("solrPublish")
	public void solrPublish(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String r ="yes";
		try {
			dynamicService.saveObjectForCache();
		} catch (Exception e) {
			r="no";
		}
		List<String> list = new ArrayList<String>();
		list.add(r);
		String resultString = formatToJson(list);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	
	/**
	 * 客户资料
	 */
	/**
	 * 修改 页面
	 * zhongfeng
	 * 2016.9.12
	 * @throws UnsupportedEncodingException 
	 */
	
	@RequestMapping("knowledge-edit-data-detail-update-relevance.html")
	public ModelAndView toknowledgeEditDataDetailUpdateRelevance(HttpServletRequest request) throws UnsupportedEncodingException {
		
		// 三级。如矿石等
		String classesEn = request.getParameter("classesEn");
		String classesId = request.getParameter("classesId");
		String dynamicDataId = request.getParameter("id");
		String createUserId = request.getParameter("createUserId");
		String curr = request.getParameter("curr");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		String searchType = request.getParameter("searchType");
		String status = request.getParameter("status");
		/*JSONObject jb = JSONObject.fromObject(screenContent);
		Map screenContentmap = (Map)jb;
		HashMap<String, Object> conditions = new HashMap<String, Object>();
		for (Object key : screenContentmap.keySet()) {
			conditions.put(key.toString(), screenContentmap.get(key));
		}*/
		 User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		HashMap<String, Object> queryParamsUser = new HashMap<String, Object>();
		queryParamsUser.put("=,userId",  user.getId());
		List<UserRole> userRole = publicService.getUserRole(queryParamsUser);
		String roleName="";
		if(userRole != null && userRole.size()>0){
			roleName = publicService.findRole(userRole.get(0).getRoleId()).getName();
		}
		
		Classes classes = publicService.findClasses(Integer.parseInt(classesId));
		// 标题
		String headline= classes.getNameZh();
		// 描述
		String describe = classes.getDescription();
		List<DataProperty> dataProperties = publicService.getDataProperty(classes);
		List<DataType> dataType = publicService.getDataType();
		String select="";
		for(DataProperty dp : dataProperties){ 
			if("1".equals(dp.getAdminListShow()) && request.getParameter(dp.getNameEn()) !=null && !"".equals(request.getParameter(dp.getNameEn()))){
				String selectValue =request.getParameter(dp.getNameEn());
				if(selectValue !=null && !"".equals(selectValue)){
					select += "&"+dp.getNameEn()+"="+selectValue;
				}
			}
		}
		if(createUserId !=null && !"".equals(createUserId)){
			select += "&createUserId="+createUserId;
		}
		if(curr !=null && !"".equals(curr)){
			select += "&curr="+curr;
		}
		if(startTime !=null && !"".equals(startTime)){
			select += "&startTime="+startTime;
		}
		if(endTime !=null && !"".equals(endTime)){
			select += "&endTime="+endTime;
		}
		if(searchType !=null && !"".equals(searchType)){
			select += "&searchType="+searchType;
		}
		if(status !=null && !"".equals(status)){
			select += "&status="+status;
		}
		Map<String, Object> data = dynamicService.findDynamicData(classesEn,dynamicDataId);
		HashMap<String, Object> picturePath =  new LinkedHashMap<String, Object>();
		
		//获取服务器地址
		 String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		 String adjunctPath =  request.getContextPath() + "/adjunct/";
		//字典
		 
		 List<Map<String, Object>> arrList = new ArrayList<Map<String,Object>>();
		 List<Map<Object, Object>> dicNameEn = new ArrayList<Map<Object,Object>>();
		 Map<String, Object> multiList = new LinkedHashMap<String, Object>();
		//List<DictItem> DictItem =new ArrayList<DictItem>();
		 Map<Integer, Integer> dictsMap = new HashMap<Integer, Integer>();
			for(DataProperty dp : dataProperties){
				dp.setNameEn(dp.getNameEn());
				
				if(null == dp.getFormValidationRegulation()){
					dp.setFormValidationRegulation("");
				}
				Integer dataTypeId= dp.getDataTypeId();
				Integer dictId=dp.getDictId();
				if(dictId != 0){
					Dict dicts = publicService.findDict(dictId);
					dictsMap.put(dp.getDictId(), dicts.getDictType());
					if(dicts.getDictType()==2){
						Map<Object, Object> dicNameEnMap = new HashMap<Object, Object>();
						dicNameEnMap.put("dictDpId", dp.getNameEn());
						dicNameEn.add(dicNameEnMap);
					}
					Dict dict = new Dict();
					dict.setId(dictId);
					List<DictItem> dictItem = publicService.getDictItem(dict);
					for(DictItem dic : dictItem){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("dpid", dp.getId());
						map.put("dicid", dic.getId());
						map.put("nameZh", dic.getNameZh());
						map.put("value", dic.getValue());
						arrList.add(map);
					}
					Object multis = data.get(dp.getNameEn());
					String multiname="";
					if(multis!=null && !"".equals(multis)){
						String [] multimap = multis.toString().split(",");
						for (int i = 0; i < multimap.length; i++) {
							HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
							queryParams.put("=,dict_id", dp.getDictId());
							queryParams.put("=,value", multimap[i]);
							List<DictItem> aDictItems =publicService.getDictItem(queryParams, 1, publicService.getDictItemCount(queryParams));
							if(aDictItems.size()>0){
								DictItem aDictItem = aDictItems.get(0);
								multiname += aDictItem.getNameZh()+",";
							}
						}
						if(!"".equals(multiname) && multiname != null){
							multiname = multiname.substring(0, multiname.length()-1);
							multiList.put(dp.getNameEn(), multiname);
						}
					}
				}
				//dp.setDataType(publicService.findDataType(dataTypeId));
				
				if(dp.getDataTypeId() != null && dp.getDataTypeId()==16){
					String wenjian = (String) data.get(dp.getNameEn());
					if(wenjian != null && !"".equals(wenjian)){
						String [] wenjiansz =wenjian.split("%");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian ="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						data.put(dp.getNameEn(), danwenjian);
						picturePath.put(dp.getNameEn(), wenjian);
					}else{
						picturePath.put(dp.getNameEn(), wenjian);
					}				}
				if(dp.getDataTypeId() != null && dp.getDataTypeId()==17 ){
					String wenjian = (String) data.get(dp.getNameEn());
					if(wenjian != null && !"".equals(wenjian)){
						String [] wenjiansz =wenjian.split("%");
						String danwenjian = "";
						for (int j = 0; j < wenjiansz.length; j++) {
							if(wenjiansz[j] != null && !"".equals(wenjiansz[j])){
								danwenjian +="<a href="+uploadPath+wenjiansz[j]+" download='w3logo' target='_blank' title='点击下载'><img src='static/images/wj.jpg' width='30' height='30' /></a>";
							}
						}
						data.put(dp.getNameEn(), danwenjian);
						picturePath.put(dp.getNameEn(), wenjian);
					}else{
						picturePath.put(dp.getNameEn(), wenjian);
					}
				}
				if(dp.getDataTypeId() == 5 || dp.getDataTypeId() == 6 ){
					String path = (String) data.get(dp.getNameEn());
					if(path != null && !"".equals(path)){
						String url = CommonUrl.addPrefixPath("src", path, uploadPath);
						data.put(dp.getNameEn(), url);
					}
				}
			}
		//导航
		List<Classes> objectPropertyClasses = publicService.getClasses();
		List<ObjectProperty> objectProperty = publicService.getObjectProperty(classes);
			for(ObjectProperty op :objectProperty){
				//op.setRelevanceClasses(publicService.findClasses(op.getRelevanceClassesId()));
			}
		/*String dicValue=null;
		if(dicNameEn !=null){
			
			dicValue=(String) data.get(dicNameEn);
		
		}*/
		for (int i = 0; i < dicNameEn.size(); i++) {
			Map<Object, Object> dic =dicNameEn.get(i);
			dic.put("jieguoji", data.get(dic.get("dictDpId")));
			
		}
		
		for(DataProperty dp : dataProperties){
			if(data.get(dp.getNameEn()) == null){
				data.put(dp.getNameEn(), "");
			}
		}
		ModelAndView view = new ModelAndView();
		view.addObject("classesEn", classesEn);
		view.addObject("classesId", classesId);
		view.addObject("idString", dynamicDataId);
		view.addObject("headline", headline);
		view.addObject("describe", describe);
		view.addObject("dataProperties", dataProperties);
		view.addObject("data", data);
		//view.addObject("DictItem", DictItem);
		view.addObject("resultString", arrList);
		view.addObject("dataType", dataType);
		view.addObject("dictsMap", dictsMap);
		view.addObject("dicValue", dicNameEn);
		view.addObject("uploadPath", uploadPath);
		view.addObject("objectProperty", objectProperty);
		view.addObject("objectPropertyClasses", objectPropertyClasses);
		view.addObject("adjunctPath", adjunctPath);
		view.addObject("multiList", multiList);
		view.addObject("picturePath", picturePath);
		view.addObject("screenContent", select);
		view.addObject("roleName", roleName);
		view.setViewName("/modules/repository/knowledge_edit_data_detail_update_relevance");
		return view;
	}
	/**
	 * 文件转换PDF
	 */
	@RequestMapping("fileToPdf")
	public void fileToPdf(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String urlFile = request.getParameter("urlFile");
		//获取服务器地址
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		String filePath =  XxlConfClient.get("dal.file.path", "") ;
		String savePath = urlFile.substring(0, urlFile.lastIndexOf("/")).replaceAll(uploadPath, filePath); 
		String name = urlFile.substring(urlFile.lastIndexOf("/")+1,urlFile.lastIndexOf("."));
		String inputFile = urlFile.replaceAll(uploadPath, filePath);
		String outFile = savePath+"/"+name+".pdf";
		String result = "yes";
		try {
			OpenOfficePdfConvert.office2PDF(inputFile,outFile);
		} catch (Exception e) {
			e.printStackTrace();
			result = "no";
		}
		
		List<String> list = new ArrayList<String>();
		if("yes".equals(result)){
			list.add(outFile.replaceAll(filePath, uploadPath));
		}
		String resultString = formatToJson(list);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	/**
	 * @author zf
	 * @return WorkflowExecuteList
	 * 查询审核列表
	 * 2018年4月21日13:54:45
	 */
	@RequestMapping("getWorkflowExecute")
	public void getWorkflowExecute(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String page = request.getParameter("page");
		String classnameEn = request.getParameter("classnameEn");
		String text = request.getParameter("text");
		String databaseId = request.getParameter("databaseId");
		String chartName = request.getParameter("chartName");
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		//分库分表
		String tableactiondTab = "";
		String tableactionTabContent = "";
		String newsTab = "";
		HashMap<String, Object> queryRepositoryCountParams = new HashMap<String, Object>();
		queryRepositoryCountParams.put("=,classes_en", classnameEn);
		HashMap<String, Object> tableNameMap= new LinkedHashMap<String, Object>();
		List<ShardingRepositoryCount> ShardingRepositoryCountList = publicService.getShardingRepositoryCount(queryRepositoryCountParams, 1, publicService.getShardingRepositoryCountCount(queryRepositoryCountParams));
		for (int i = 0; i < ShardingRepositoryCountList.size(); i++) {
			ShardingRepositoryCount shardingRepositoryCount = ShardingRepositoryCountList.get(i);
			ShardingDataSource ShardingDataSource = publicService.findShardingDataSource(shardingRepositoryCount.getShardingDataSourceId());
			if(null == tableNameMap.get(ShardingDataSource.getNameEn()) || "".equals(tableNameMap.get(ShardingDataSource.getNameEn()))){
				if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
					if(databaseId.equals(ShardingDataSource.getId().toString()) ){
						newsTab = ShardingDataSource.getNameEn();
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle on\" value=\""+ShardingDataSource.getNameZh()+"\" >&nbsp;&nbsp;&nbsp;";
					}else{
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle\" value=\""+ShardingDataSource.getNameZh()+"\" >&nbsp;&nbsp;&nbsp;";
					}
				}else {
					if(i == 0){
						newsTab = ShardingDataSource.getNameEn();
						databaseId= ShardingDataSource.getId().toString();
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle on\" value=\""+ShardingDataSource.getNameZh()+"\" >&nbsp;&nbsp;&nbsp;";
					}else{
						tableactiondTab += "<input type=\"button\" data-value=\""+ShardingDataSource.getId()+"\" data-name=\"#table-"+ShardingDataSource.getNameEn()+"-tab\" class=\"btn btn-default dropdown-toggle\" value=\""+ShardingDataSource.getNameZh()+"\" >&nbsp;&nbsp;&nbsp;";
					}
				}
			}
			if(null == tableNameMap.get(ShardingDataSource.getNameEn()) || "".equals(tableNameMap.get(ShardingDataSource.getNameEn()))){
				tableNameMap.put(ShardingDataSource.getNameEn(), shardingRepositoryCount.getTableName());
			}else{
				tableNameMap.put(ShardingDataSource.getNameEn(),tableNameMap.get(ShardingDataSource.getNameEn())+";"+shardingRepositoryCount.getTableName());
			}
		}
		for (String tableName : tableNameMap.keySet()) {
			Object oTableName = tableNameMap.get(tableName);
			if(null != oTableName && !"".equals(oTableName)){
				String [] tableNames = oTableName.toString().split(";");
				if(tableName.equals(newsTab)){
					tableactionTabContent +="<div id=\"table-"+tableName+"-tab\" class=\"tab-pane fade in active\">"
	                                    	+"<div class=\"row\">"
	                                    	+"<div class=\"col-lg-12\">";
											for (int i = 0; i < tableNames.length; i++) {
												if(null != chartName && !"".equals(chartName)&& !"undefined".equals(chartName)){
													if(chartName.equals(tableNames[i])){
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default on\" />&nbsp;&nbsp;&nbsp;";
													}else{
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default\" />&nbsp;&nbsp;&nbsp;";
													}
												}else{
													if( i == 0){
														chartName = tableNames[i];
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default on\" />&nbsp;&nbsp;&nbsp;";
													}else{
														tableactionTabContent +="<input type=\"button\" value=\""+tableNames[i]+"\" data-value=\""+tableNames[i]+"\" class=\"btn btn-default\" />&nbsp;&nbsp;&nbsp;";
													}
												}
											}
					  tableactionTabContent +="</div>"
	                                    	+"</div>"
	                                    	+"</div>";
				}else{
					tableactionTabContent +="<div id=\"table-"+tableName+"-tab\" class=\"tab-pane fade \">"
	                    	+"<div class=\"row\">"
	                    	+"<div class=\"col-lg-12\">";
							for (int i = 0; i < tableNames.length; i++) {
								tableactionTabContent +="<input type=\"button\" data-value=\""+tableNames[i]+"\" value=\""+tableNames[i]+"\" class=\"btn btn-default \" />&nbsp;&nbsp;&nbsp;";
							}
	  tableactionTabContent +="</div>"
	                    	+"</div>"
	                    	+"</div>";
				}
			}
		}
		
		Map<String,Object> data = new HashMap<String, Object>();//返回结果
		
		HashMap<String, Object> conditions = new HashMap<String, Object>();
		conditions.put("=submit_user_id", user.getId());
		conditions.put("=status", 2);
		if(null != text && !"".equals(text)){
			conditions.put("title", text);
		}
		if(null != ShardingRepositoryCountList && ShardingRepositoryCountList.size()>0){
				ShardingRepositoryCount shardingRepositoryCount = null;
				if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
					HashMap<String, Object> queryRepositoryCountParams2 = new HashMap<String, Object>();
					queryRepositoryCountParams2.put("=,sharding_data_source_id", databaseId);
					queryRepositoryCountParams2.put("=,table_name", chartName);
					List<ShardingRepositoryCount> ShardingRepositoryCountList2 = publicService.getShardingRepositoryCount(queryRepositoryCountParams2, 1, 1);
					if(null != ShardingRepositoryCountList2 && ShardingRepositoryCountList2.size()>0){
						shardingRepositoryCount = ShardingRepositoryCountList2.get(0);
					}
				}else{
					shardingRepositoryCount = ShardingRepositoryCountList.get(0);
				}
				List<Map<String,Object>> list=dynamicService.getDynamicData(classnameEn, conditions, "id", "desc", Integer.parseInt(page), 10,shardingRepositoryCount.getShardingDataSourceId().toString(),shardingRepositoryCount.getTableName());
				for (int i = 0; i < list.size(); i++) {
					Map<String,Object> map = list.get(i);
					String createUserId = map.get("create_user_id").toString();
					User userMap = publicService.findUser(Integer.parseInt(createUserId));
					if(null != userMap){
						map.put("create_user_id", userMap.getNickname());
					}else{
						map.put("create_user_id", "");
					}
					
					map.put("databaseId", databaseId);
					map.put("chartName", chartName);
				}
				long pageCount = dynamicService.getDynamicCount(classnameEn, conditions,shardingRepositoryCount.getShardingDataSourceId().toString(),shardingRepositoryCount.getTableName());
				data.put("data", list);
				data.put("pageCount", pageCount);
				data.put("page",(int)Math.ceil(Double.valueOf(pageCount)/10));
		}else{
			List<Map<String,Object>> list= dynamicService.getDynamicData(classnameEn, conditions, "id", "desc", Integer.parseInt(page), 10);
			for (int i = 0; i < list.size(); i++) {
				Map<String,Object> map = list.get(i);
				String createUserId = map.get("create_user_id").toString();
				User userMap = publicService.findUser(Integer.parseInt(createUserId));
				if(null != userMap){
					map.put("create_user_id", userMap.getNickname());
				}else{
					map.put("create_user_id", "");
				}
				map.put("databaseId", databaseId);
				map.put("chartName", chartName);
			}
			long pageCount = dynamicService.getDynamicCount(classnameEn, conditions);
			data.put("data", list);
			data.put("pageCount", pageCount);
			data.put("page",(int)Math.ceil(Double.valueOf(pageCount)/10));
		}
		
		data.put("tableactiondTab", tableactiondTab);
		data.put("tableactionTabContent", tableactionTabContent);
		String resultString = formatToJson(data);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	/**
	 * @author zf
	 * @return WorkflowExecuteList
	 * 查询审核--不通过
	 * 2018年4月21日17:45:59
	 */
	@RequestMapping("toAuditNoPass")
	public void toAuditNoPass(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String classnameEn = request.getParameter("classnameEn");
		String pass = request.getParameter("pass");
		String databaseId = request.getParameter("databaseId");
		String chartName = request.getParameter("chartName");
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		String createTime = DateUtils.getDateTime();
		String returnid="yes";
		//添加审核记录
		HashMap<String, Object> queryWorkflowParams = new HashMap<String, Object>();
		queryWorkflowParams.put("=,classes_en", classnameEn);
		queryWorkflowParams.put("=,status", 1);
		List<Workflow> workflowList = publicService.getWorkflow(queryWorkflowParams, 1, 1);
		if(null != workflowList && workflowList.size()>0){
			Workflow workflow = workflowList.get(0);
			HashMap<String, Object> queryWorkflowNodeParams = new HashMap<String, Object>();
			queryWorkflowNodeParams.put("=,executor", user.getUsername());
			queryWorkflowNodeParams.put("=,workflow_id", workflow.getId());
			List<WorkflowNode> workflowNodeList = publicService.getWorkflowNode(queryWorkflowNodeParams, 1, 1);
			if(null != workflowNodeList && workflowNodeList.size()>0){
				WorkflowNode workflowNode = workflowNodeList.get(0);
				WorkflowExecute workflowExecute = new WorkflowExecute();
				workflowExecute.setClassesEn(classnameEn);
				workflowExecute.setCreateTime(createTime);
				workflowExecute.setCreateUser(user.getUsername());
				workflowExecute.setReason(pass);
				workflowExecute.setResourceId(id);
				workflowExecute.setWorkflowId(workflow.getId());
				workflowExecute.setWorkflowNodeId(workflowNode.getId());
				workflowExecute.setStatus(0);
				publicService.saveWorkflowExecute(workflowExecute);
			}
		}
		List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
			if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
				dataList.add(dynamicService.findDynamicData(classnameEn, id,databaseId,chartName));
			}else{
				dataList.add(dynamicService.findDynamicData(classnameEn, id));
			}
		for (int i = 0; i < dataList.size(); i++) {
			Map dynamic = dataList.get(i);
				String dataid = dynamic.get("id").toString();
				dynamic.remove("updateTime");
				dynamic.remove("updateUserId");
				dynamic.remove("status");
				dynamic.remove("version");
				dynamic.remove("id");
				dynamic.remove("createTime");
				dynamic.remove("submitTime");
				dynamic.remove("createUserId");
				dynamic.remove("submitUserId");
				dynamic.remove("dataSource");
				dynamic.remove("classesId");
				dynamic.remove("updateOrgId");
				dynamic.remove("createOrgId");
				dynamic.remove("submitOrgId");
				HashMap data = new HashMap();
				for(Object key: dynamic.keySet()){
					data.put(key.toString(), dynamic.get(key));
				}
				Integer departmentid =(Integer) request.getSession().getAttribute("userid");
				String updateUserId = departmentid.toString();
				String version = "1.0";
				String updateTime = DateUtils.getDateTime();
				try {
					if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
						dynamicService.editDynamicData(classnameEn, data, updateTime, updateUserId, "0", version, dataid,databaseId,chartName);
					}else{
						dynamicService.editDynamicData(classnameEn, data, updateTime, updateUserId, "0", version, dataid);
					}
					//dynamicService.submitDynamicData(classesEn, updateTime,updateUserId, id);
				} catch (Exception e) {
					returnid="no";
				}
				
		}
		List<String> r = new ArrayList<String>();
		r.add(returnid);
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	/**
	 * @author zf
	 * @return List
	 * 查询审核--通过
	 * 2018年4月21日17:45:59
	 */
	@RequestMapping("toAuditYesPass")
	public void toAuditYesPass(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String classnameEn = request.getParameter("classnameEn");
		String databaseId = request.getParameter("databaseId");
		String chartName = request.getParameter("chartName");
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		String createTime = DateUtils.getDateTime();
		String returnid="yes";
		String status = "1";
		String executor = "";
		String submitTime = "";
		//添加审核记录
		HashMap<String, Object> queryWorkflowParams = new HashMap<String, Object>();
		queryWorkflowParams.put("=,classes_en", classnameEn);
		queryWorkflowParams.put("=,status", 1);
		List<Workflow> workflowList = publicService.getWorkflow(queryWorkflowParams, 1, 1);
		if(null != workflowList && workflowList.size()>0){
			Workflow workflow = workflowList.get(0);
			HashMap<String, Object> queryWorkflowNodeParams = new HashMap<String, Object>();
			queryWorkflowNodeParams.put("=,executor", user.getUsername());
			queryWorkflowNodeParams.put("=,workflow_id", workflow.getId());
			List<WorkflowNode> workflowNodeList = publicService.getWorkflowNode(queryWorkflowNodeParams, 1, 1);
			if(null != workflowNodeList && workflowNodeList.size()>0){
				WorkflowNode workflowNode = workflowNodeList.get(0);
				WorkflowExecute workflowExecute = new WorkflowExecute();
				workflowExecute.setClassesEn(classnameEn);
				workflowExecute.setCreateTime(createTime);
				workflowExecute.setCreateUser(user.getUsername());
				workflowExecute.setReason("通过");
				workflowExecute.setResourceId(id);
				workflowExecute.setWorkflowId(workflow.getId());
				workflowExecute.setWorkflowNodeId(workflowNode.getId());
				workflowExecute.setStatus(1);
				publicService.saveWorkflowExecute(workflowExecute);
				
				//查询下一步审核人
				HashMap<String, Object> queryWorkflowNodeParams2 = new HashMap<String, Object>();
				queryWorkflowNodeParams2.put("=,sort", (workflowNode.getSort()+1));
				queryWorkflowNodeParams2.put("=,workflow_id", workflow.getId());
				List<WorkflowNode> workflowNodeList2 = publicService.getWorkflowNode(queryWorkflowNodeParams2, 1, 1);
				if(null != workflowNodeList2 && workflowNodeList2.size()>0){
					status = "2";
					HashMap<String, Object> queryUserParams = new HashMap<String, Object>();
					queryUserParams.put("=,username", workflowNodeList2.get(0).getExecutor());
					List<User> userList= publicService.getUser(queryUserParams, 1, 1);
					if(null != userList && userList.size()>0){
						executor = userList.get(0).getId().toString();
					}
				}else{
					submitTime=DateUtils.getDateTime();
					HashMap<String, Object> queryUserParams = new HashMap<String, Object>();
					queryUserParams.put("=,username", workflowNode.getExecutor());
					List<User> userList= publicService.getUser(queryUserParams, 1, 1);
					if(null != userList && userList.size()>0){
						executor = userList.get(0).getId().toString();
					}
				}
			}
		}
		List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
		if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
			dataList.add(dynamicService.findDynamicData(classnameEn, id,databaseId,chartName));
		}else{
			dataList.add(dynamicService.findDynamicData(classnameEn, id));
		}
		for (int i = 0; i < dataList.size(); i++) {
			Map dynamic = dataList.get(i);
			String dataid = dynamic.get("id").toString();
			dynamic.remove("updateTime");
			dynamic.remove("updateUserId");
			dynamic.remove("status");
			dynamic.remove("version");
			dynamic.remove("id");
			dynamic.remove("createTime");
			dynamic.remove("submitTime");
			dynamic.remove("createUserId");
			dynamic.remove("submitUserId");
			dynamic.remove("dataSource");
			dynamic.remove("classesId");
			dynamic.remove("updateOrgId");
			dynamic.remove("createOrgId");
			dynamic.remove("submitOrgId");
			HashMap data = new HashMap();
			for(Object key: dynamic.keySet()){
				data.put(key.toString(), dynamic.get(key));
			}
			data.put("submit_user_id", executor);
			data.put("submit_time", submitTime);
			Integer departmentid =(Integer) request.getSession().getAttribute("userid");
			String updateUserId = departmentid.toString();
			String version = "1.0";
			String updateTime = DateUtils.getDateTime();
			try {
				if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
					dynamicService.editDynamicData(classnameEn, data, updateTime, updateUserId, status, version, dataid,databaseId,chartName);
				}else{
					dynamicService.editDynamicData(classnameEn, data, updateTime, updateUserId, status, version, dataid);
				}
				//dynamicService.submitDynamicData(classesEn, updateTime,updateUserId, id);
			} catch (Exception e) {
				returnid="no";
			}
			
		}
		List<String> r = new ArrayList<String>();
		r.add(returnid);
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	//批量审核通过
	@RequestMapping("batchAuditYes")
	public void batchAuditYes(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String[] values =request.getParameterValues("value");
		String classnameEn = request.getParameter("classnameEn");
		String databaseId = request.getParameter("databaseId");
		String chartName = request.getParameter("chartName");
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		String createTime = DateUtils.getDateTime();
		String returnid="yes";
		String status = "1";
		String executor = "";
		String submitTime = "";
		//添加审核记录
		HashMap<String, Object> queryWorkflowParams = new HashMap<String, Object>();
		queryWorkflowParams.put("=,classes_en", classnameEn);
		queryWorkflowParams.put("=,status", 1);
		List<Workflow> workflowList = publicService.getWorkflow(queryWorkflowParams, 1, 1);
		if(null != workflowList && workflowList.size()>0){
			Workflow workflow = workflowList.get(0);
			HashMap<String, Object> queryWorkflowNodeParams = new HashMap<String, Object>();
			queryWorkflowNodeParams.put("=,executor", user.getUsername());
			queryWorkflowNodeParams.put("=,workflow_id", workflow.getId());
			List<WorkflowNode> workflowNodeList = publicService.getWorkflowNode(queryWorkflowNodeParams, 1, 1);
			if(null != workflowNodeList && workflowNodeList.size()>0){
				WorkflowNode workflowNode = workflowNodeList.get(0);
				WorkflowExecute workflowExecute = null;
				for (int i = 0; i < values.length; i++) {
					workflowExecute = new WorkflowExecute();
					workflowExecute.setClassesEn(classnameEn);
					workflowExecute.setCreateTime(createTime);
					workflowExecute.setCreateUser(user.getUsername());
					workflowExecute.setReason("通过");
					workflowExecute.setResourceId(values[i]);
					workflowExecute.setWorkflowId(workflow.getId());
					workflowExecute.setWorkflowNodeId(workflowNode.getId());
					workflowExecute.setStatus(1);
					publicService.saveWorkflowExecute(workflowExecute);
				}
				//查询下一步审核人
				HashMap<String, Object> queryWorkflowNodeParams2 = new HashMap<String, Object>();
				queryWorkflowNodeParams2.put("=,sort", (workflowNode.getSort()+1));
				queryWorkflowNodeParams2.put("=,workflow_id", workflow.getId());
				List<WorkflowNode> workflowNodeList2 = publicService.getWorkflowNode(queryWorkflowNodeParams2, 1, 1);
				if(null != workflowNodeList2 && workflowNodeList2.size()>0){
					status = "2";
					HashMap<String, Object> queryUserParams = new HashMap<String, Object>();
					queryUserParams.put("=,username", workflowNodeList2.get(0).getExecutor());
					List<User> userList= publicService.getUser(queryUserParams, 1, 1);
					if(null != userList && userList.size()>0){
						executor = userList.get(0).getId().toString();
					}
				}else{
					submitTime=DateUtils.getDateTime();
					HashMap<String, Object> queryUserParams = new HashMap<String, Object>();
					queryUserParams.put("=,username", workflowNode.getExecutor());
					List<User> userList= publicService.getUser(queryUserParams, 1, 1);
					if(null != userList && userList.size()>0){
						executor = userList.get(0).getId().toString();
					}
				}
			}
		}
		List<Map<String,Object>> dataList =  new ArrayList<Map<String,Object>>();
		for (int j = 0; j < values.length; j++) {
			if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
				dataList.add(dynamicService.findDynamicData(classnameEn, values[j],databaseId,chartName));
			}else{
				dataList.add(dynamicService.findDynamicData(classnameEn, values[j]));
			}
		}
		for (int i = 0; i < dataList.size(); i++) {
			Map dynamic = dataList.get(i);
			String dataid = dynamic.get("id").toString();
			dynamic.remove("updateTime");
			dynamic.remove("updateUserId");
			dynamic.remove("status");
			dynamic.remove("version");
			dynamic.remove("id");
			dynamic.remove("createTime");
			dynamic.remove("submitTime");
			dynamic.remove("createUserId");
			dynamic.remove("submitUserId");
			dynamic.remove("dataSource");
			dynamic.remove("classesId");
			dynamic.remove("updateOrgId");
			dynamic.remove("createOrgId");
			dynamic.remove("submitOrgId");
			HashMap data = new HashMap();
			for(Object key: dynamic.keySet()){
				data.put(key.toString(), dynamic.get(key));
			}
			data.put("submit_user_id", executor);
			data.put("submit_time", submitTime);
			Integer departmentid =(Integer) request.getSession().getAttribute("userid");
			String updateUserId = departmentid.toString();
			String version = "1.0";
			String updateTime = DateUtils.getDateTime();
			try {
				if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
					dynamicService.editDynamicData(classnameEn, data, updateTime, updateUserId, status, version, dataid,databaseId,chartName);
				}else{
					dynamicService.editDynamicData(classnameEn, data, updateTime, updateUserId, status, version, dataid);
				}
				//dynamicService.submitDynamicData(classesEn, updateTime,updateUserId, id);
			} catch (Exception e) {
				returnid="no";
			}
		}
		
		List<String> r = new ArrayList<String>();
		r.add(returnid);
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	/**
	 * @author zf
	 * @return WorkflowExecuteList
	 * 批量审核--不通过
	 * 2018年4月21日17:45:59
	 */
	@RequestMapping("batchAuditNo")
	public void batchAuditNo(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String[] values =request.getParameterValues("value");
		String classnameEn = request.getParameter("classnameEn");
		String pass = request.getParameter("pass");
		String databaseId = request.getParameter("databaseId");
		String chartName = request.getParameter("chartName");
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		String createTime = DateUtils.getDateTime();
		String returnid="yes";
		//添加审核记录
		HashMap<String, Object> queryWorkflowParams = new HashMap<String, Object>();
		queryWorkflowParams.put("=,classes_en", classnameEn);
		queryWorkflowParams.put("=,status", 1);
		List<Workflow> workflowList = publicService.getWorkflow(queryWorkflowParams, 1, 1);
		if(null != workflowList && workflowList.size()>0){
			Workflow workflow = workflowList.get(0);
			HashMap<String, Object> queryWorkflowNodeParams = new HashMap<String, Object>();
			queryWorkflowNodeParams.put("=,executor", user.getUsername());
			queryWorkflowNodeParams.put("=,workflow_id", workflow.getId());
			List<WorkflowNode> workflowNodeList = publicService.getWorkflowNode(queryWorkflowNodeParams, 1, 1);
			if(null != workflowNodeList && workflowNodeList.size()>0){
				WorkflowNode workflowNode = workflowNodeList.get(0);
				WorkflowExecute workflowExecute = null;
				for (int i = 0; i < values.length; i++) {
					workflowExecute = new WorkflowExecute();
					workflowExecute.setClassesEn(classnameEn);
					workflowExecute.setCreateTime(createTime);
					workflowExecute.setCreateUser(user.getUsername());
					workflowExecute.setReason(pass);
					workflowExecute.setResourceId(values[i]);
					workflowExecute.setWorkflowId(workflow.getId());
					workflowExecute.setWorkflowNodeId(workflowNode.getId());
					workflowExecute.setStatus(0);
					publicService.saveWorkflowExecute(workflowExecute);
				}
			}
		}
		List<Map<String,Object>> dataList =  new ArrayList<Map<String,Object>>();
		for (int j = 0; j < values.length; j++) {
			if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
				dataList.add(dynamicService.findDynamicData(classnameEn, values[j],databaseId,chartName));
			}else{
				dataList.add(dynamicService.findDynamicData(classnameEn, values[j]));
			}
		}
		for (int i = 0; i < dataList.size(); i++) {
			Map dynamic = dataList.get(i);
			String dataid = dynamic.get("id").toString();
			dynamic.remove("updateTime");
			dynamic.remove("updateUserId");
			dynamic.remove("status");
			dynamic.remove("version");
			dynamic.remove("id");
			dynamic.remove("createTime");
			dynamic.remove("submitTime");
			dynamic.remove("createUserId");
			dynamic.remove("submitUserId");
			dynamic.remove("dataSource");
			dynamic.remove("classesId");
			dynamic.remove("updateOrgId");
			dynamic.remove("createOrgId");
			dynamic.remove("submitOrgId");
			HashMap data = new HashMap();
			for(Object key: dynamic.keySet()){
				data.put(key.toString(), dynamic.get(key));
			}
			Integer departmentid =(Integer) request.getSession().getAttribute("userid");
			String updateUserId = departmentid.toString();
			String version = "1.0";
			String updateTime = DateUtils.getDateTime();
			try {
				if(null != databaseId && !"".equals(databaseId)&& !"undefined".equals(databaseId)){
					dynamicService.editDynamicData(classnameEn, data, updateTime, updateUserId, "0", version, dataid,databaseId,chartName);
				}else{
					dynamicService.editDynamicData(classnameEn, data, updateTime, updateUserId, "0", version, dataid);
				}
				//dynamicService.submitDynamicData(classesEn, updateTime,updateUserId, id);
			} catch (Exception e) {
				returnid="no";
			}
		}
		
		List<String> r = new ArrayList<String>();
		r.add(returnid);
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	
	/**
	* method: revocationProcess
	* Description: 批量撤销数据
	* @author 邢天龙
	* @date 2018年5月18日 下午4:23:57
	* @version 1.0
	 */
	@RequestMapping("batchRevocationProcess")
	@ResponseBody
	public void revocationProcess(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String result="success";
		String[] users =request.getParameterValues("user");
		List<String> r = new ArrayList<String>();
		try {
			String classesEn = request.getParameter("classesEn");
			String[] ids = request.getParameterValues("id");
			Integer departmentid =(Integer) request.getSession().getAttribute("userid");
			String updateUserId = departmentid.toString();
			SimpleDateFormat format=new SimpleDateFormat("yyyyy-MM-dd HH:mm:ss");
			for (int i = 0; i < ids.length; i++) {
				Map<String, Object> data = dynamicService.findDynamicData(classesEn,ids[i]);
				Map map=new HashMap();
				if(data.size()>0){
					if(null!=users&&users.length>0)
					{
					map.put("create_user_id",users[0]);	
					}
					map.put("status",6);	
					map.put("submit_time", "");
				    HashMap<String, Object> WorkflowExecuteMap = new HashMap<String, Object>();
				    WorkflowExecuteMap.put("=,resource_id", ids[i]);
				    List<WorkflowExecute> workflowExecuteList = publicService.getWorkflowExecute(WorkflowExecuteMap, 1, Integer.MAX_VALUE);
				    Iterator<WorkflowExecute> iterator = workflowExecuteList.iterator();
				    while(iterator.hasNext()){
				     WorkflowExecute workflowExecute=iterator.next();
				     publicService.deleteWorkflowExecute(workflowExecute);
				    }
			      	dynamicService.editDynamicData(classesEn,map,format.format(new Date()),updateUserId,data.get("status").toString(),data.get("version").toString(),ids[i]);
			  }
	     }
		} catch (Exception e) {
			result="fail";
			e.printStackTrace();
			
		}
	
		r.add(result);
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	} 
	
	@RequestMapping("toSubmitData")
	@ResponseBody
	public void submitData(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String[] ids = request.getParameterValues("id");
		String classesEn = request.getParameter("classesEn");
	    HashMap<String, Object> WorkflowExecuteMap = new HashMap<String, Object>();
		for (int i = 0; i < ids.length; i++) {
		    WorkflowExecuteMap.put("=,resource_id", ids[i]);
		    WorkflowExecuteMap.put("^,create_time", "desc");
			Map<String, Object> data = dynamicService.findDynamicData(classesEn,ids[i]);
			Integer departmentid =(Integer) request.getSession().getAttribute("userid");
			String updateUserId = departmentid.toString();
			String version = "1.0";
			String updateTime = DateUtils.getDateTime();
			
			data.remove("status");
		
			dynamicService.editDynamicData(classesEn, data,updateTime, updateUserId, "2", version,ids[i]);
		}
		  
	 
		
	}
	@RequestMapping("xiajiaMethod")
	@ResponseBody
	public void xiajiaMethod(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String[] ids = request.getParameterValues("id");
		String classesEn = request.getParameter("classesEn");
	    HashMap<String, Object> WorkflowExecuteMap = new HashMap<String, Object>();
		for (int i = 0; i < ids.length; i++) {
		    WorkflowExecuteMap.put("=,resource_id", ids[i]);
		    WorkflowExecuteMap.put("^,create_time", "desc");
			Map<String, Object> data = dynamicService.findDynamicData(classesEn,ids[i]);
			Integer departmentid =(Integer) request.getSession().getAttribute("userid");
			String updateUserId = departmentid.toString();
			String version = "1.0";
			String updateTime = DateUtils.getDateTime();
			
			data.remove("status");
		
			dynamicService.editDynamicData(classesEn, data,updateTime, updateUserId, "7", version,ids[i]);
		}
		  
	 
		
	}
	public List getJsonString(String jsonData,int workflowId) {
		org.json.JSONObject jsonObject = new  org.json.JSONObject(jsonData);
		org.json.JSONObject object = (org.json.JSONObject)jsonObject.get("lines");
 		ArrayList <String> list = new ArrayList<String>();
 		list.add("demo2_node_1");
 		String a = "demo2_node_1";
 		//if(){}
 		for(int b = 0 ;b<object.length();b++){
 			Iterator iterator = object.keys();
 			while(iterator.hasNext()){
 				org.json.JSONObject objectone = (org.json.JSONObject)object.get((String)iterator.next());
	 			String node1 = objectone.getString("from");
	 			if(node1.equals(a)){
	 				list.add(objectone.getString("to"));
	 			}
 			}
 			a=list.get(list.size()-1);
 		}
 		ArrayList <String> listtwo = new ArrayList<String>();
 		org.json.JSONObject objecttwo = (org.json.JSONObject)jsonObject.get("nodes");
 		for(int i = 0 ;i<list.size();i++){
 			org.json.JSONObject objectone = (org.json.JSONObject)objecttwo.get((String)list.get(i));
 			String name = objectone.getString("name");
 			listtwo.add(name);
 		}
 		ArrayList <Integer> endList = new ArrayList<Integer>();
 		for(String name :listtwo){
 			HashMap<String, Object> queryParams = new HashMap<String, Object>();
 			queryParams.put("=,nodeName",name);
 			queryParams.put("=,workflowId", workflowId);
 			List<WorkflowNode> workflowNode = publicService.getWorkflowNode(queryParams,1,99);
 			if(workflowNode.size()>0){
 				endList.add(workflowNode.get(0).getId());
 			}
 		}
 		return endList;
 	}
	
	/*******************************************/
	/*******    start 知识库带附件发布         **********/
	/*******************************************/
	//全库
	@RequestMapping("dataSubmitAllWithAttachment")
	public void dataSubmitAllWithAttachment(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String classesEn = request.getParameter("classesEn");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");
		String userid = request.getSession().getAttribute("userid").toString();
		String updateTime = DateUtils.getDateTime();
		List<String> r = new ArrayList<String>();
    	String succeed ="";
		try {
			if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
				//dynamicService.submitDynamicData(classesEn, updateTime, userid,databaseName,chartName);
				dynamicService.submitDynamicDataWithAttachment(classesEn, updateTime, userid, databaseName, chartName);
			}else{
				dynamicService.deleteIndexByClassesEn(classesEn);
				//dynamicService.submitDynamicData(classesEn, updateTime, userid);
				dynamicService.submitDynamicDataWithAttachment(classesEn, updateTime, userid, null, null);
			}
			succeed= "yes";
			r.add(succeed);
		} catch (Exception e) {
			succeed = "no";
			r.add(succeed);
			e.printStackTrace();
		}
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	//单个
	@RequestMapping("dataSubmitOneWithAttachment")
	public void dataSubmitOneWithAttachment(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String classesEn = request.getParameter("classesEn");
		String id = request.getParameter("id");
		String databaseName = request.getParameter("databaseName");
		String chartName = request.getParameter("chartName");
		String userid = request.getSession().getAttribute("userid").toString();
		String updateTime = DateUtils.getDateTime();
		List<String> r = new ArrayList<String>();
		String succeed ="";
		try {
			if(null != databaseName && !"".equals(databaseName)&& !"undefined".equals(databaseName)){
				//dynamicService.submitDynamicData(classesEn, updateTime,userid,id,databaseName,chartName);
				dynamicService.submitDynamicDataWithAttachment(classesEn, updateTime, userid, id, databaseName, chartName);
			}else{
				//dynamicService.submitDynamicData(classesEn, updateTime,userid,id);
				dynamicService.submitDynamicDataWithAttachment(classesEn, updateTime, userid, id, null, null);
			}
			succeed= "yes";
			r.add(succeed);
		} catch (Exception e) {
			succeed = "no";
			r.add(succeed);
			e.printStackTrace();
		}
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	}
	
	public void downloadkk(HttpServletRequest request,
			HttpServletResponse response, String fileName, String path)
			throws Exception {
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");
		response.setHeader("Content-Disposition", "attachment;fileName="
				+ fileName);
		try {
			// 这个download目录为啥建立在classes下的
			InputStream inputStream = new FileInputStream(new File(path + "/"
					+ File.separator + fileName));
			OutputStream os = response.getOutputStream();
			byte[] b = new byte[2048];
			int length;
			while ((length = inputStream.read(b)) > 0) {
				os.write(b, 0, length);
			}
			// 这里主要关闭。
			os.close();
			inputStream.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	/*******************************************/
	/*******    end   知识库带附件发布         **********/
	/*******************************************/
}
